記錄自己不知道的前端知識(shí)點(diǎn)
1.響應(yīng)式數(shù)組:
響應(yīng)式:push,pop,shift(刪除數(shù)組第一個(gè)元素),unshift,
不響應(yīng):arr[0] = 4,? 不是響應(yīng)式 。 解決辦法:1)this.$forceUpdate() ,2)Vue.set(obj, index,? value), 3)splice替換
2.函數(shù)的可變參數(shù):
fun(...data) {........} .? ? ? this.fun(55, 44, 88) .? 可以無(wú)限傳參,在函數(shù)中形成一個(gè)數(shù)組。
3.this.$forceUpdate()
可以解決數(shù)據(jù)不響應(yīng)問(wèn)題。
5.在關(guān)閉頁(yè)面時(shí)彈出確認(rèn)提示窗口onbeforeunload (原生js方法)
window.onbeforeunload?=?function(event){?? ?
? ??return?'您可能有數(shù)據(jù)沒(méi)有保存';
};
6.window.open和window.opener
window.open方法會(huì)返回一個(gè)窗口對(duì)象,使用這個(gè)對(duì)象可以向子窗口發(fā)送消息,而子窗口可以通過(guò)window.opener向父窗口發(fā)送消息,
7.window的父子頁(yè)面message跨文檔通信(低保的添加按鈕,是在點(diǎn)擊添加按鈕的時(shí)候觸發(fā)此事件,詳情頁(yè)點(diǎn)擊保存的時(shí)候調(diào)postMessage事件)
父子通信子向父postMessage的時(shí)候,源可以寫(xiě)為‘*’,父向子postMessage的時(shí)候,源需要寫(xiě)成子的源,(也就是子頁(yè)面的協(xié)議+主機(jī)號(hào)+端口)
在HTML5中新增了postMessage方法,postMessage可以實(shí)現(xiàn)跨文檔消息傳輸(Cross Document Messaging)
父頁(yè)面:
var OnMessage = function (e) {
??????????? alert(e.data);
??????? }
??????? if (window.addEventListener) {? // all browsers except IE before version 9
??????????? window.addEventListener("message", OnMessage, false);
??????? } else {
??????????? if (window.attachEvent) {?? // IE before version 9
??????????? window.attachEvent("onmessage", OnMessage);
??????????? }
??????? }
子頁(yè)面:
<script type="text/javascript">
window.parent.postMessage("hello","*");
</script>
8.覆蓋整個(gè)窗口的element的loading事件
如果完整引入了 Element,那么 Vue.prototype 上會(huì)有一個(gè)全局方法?$loading,它的調(diào)用方式為:this.$loading(options),同樣會(huì)返回一個(gè) Loading 實(shí)例。
???const?loading?=?this.$loading({
??????????????lock:?true,
??????????????background:?'rgba(255,?255,?255,?0.5)'
????????????});
9.$router.resolve()作用
$router.resolve(./../../).href? ? 獲取到一個(gè)完整的路徑,把zhjz也獲取到
10.js的對(duì)象在函數(shù)內(nèi)添加新property,
在函數(shù)外也可以獲取到該property。
11.valueof 把轉(zhuǎn)換為原始值,
就有了原始值的特性,用intanseof 檢測(cè)會(huì)返回false,intanceod用來(lái)檢測(cè)引用值的,typeof用來(lái)檢測(cè)原始值,除null,null會(huì)反復(fù)obj
12.num.toFixed()。返回小數(shù),?
如10.toFixed(2) 就返回10.00? 如果num本身是小數(shù)就10.787878 就是10.79? (四舍五入)
13.字符串翻轉(zhuǎn),
Str.split('').reverse().join('')
14.字符串檢查是否含有某個(gè)字符的方法,
startsWith(),includes(),endsWith()
var str = 'acdsw'? ? ? str.startsWith('acd')? // true? ? ? str.startsWith('sw')? // false? 只檢查字符串的開(kāi)頭,可傳第二個(gè)參數(shù)索引表示從第幾個(gè)開(kāi)始檢查開(kāi)頭有無(wú)這個(gè)字符?str.startsWith('acd', 3)
str.endsWith('acd')? // false? ? ? str.endsWith('sw')? // true // 只檢查字符串的末尾?可傳第二個(gè)參數(shù)索引表示從第幾個(gè)開(kāi)始向后全部檢查
str.includes('acd')? // true? ? ? str.includes('sw')? // true? //檢查整個(gè)字符串? ?可傳第二個(gè)參數(shù)所以標(biāo)識(shí)以索引幾位最后的結(jié)尾,查結(jié)尾是否有這個(gè)字符