1. 程式人生 > >小程式的坑記錄 點點滴滴

小程式的坑記錄 點點滴滴

1.當蓋視點設定填充屬性時邊界半徑不生效

2.獲取物件屬性的個數Object.getOwnPropertyNames(testObj)。長度

3.Vue.js當繫結事件和類名一樣時頁面一片空白也不報錯!

4.vue只能有一個根元素

5.Vue不允許在已經建立的例項上動態新增新的根級響應式屬性。

6.Vue不能檢測到物件屬性的新增或刪除或修改,最好的方式就是在初始化例項前宣告根級響應式屬性,哪怕只是一個空值。

7.使用VUE全域性方法設定物件屬性可以使VUE檢測到屬性的新增和刪除但依舊不能檢測到修改

8.陣列彈出()刪除最後一個推()新增最後一個移位()刪除第一個不印字()新增第一個

9.小程式在頁面配置css overflow-hidden頁面就不滾動了

10.vue v-if v-else v-for別掛在一個標籤使用!會爆炸

11.Vue在富文字中繫結事件在渲染出來事件不生效要這樣搞

	mounted:function(){
	  	this.$nextTick(() => {
		    // Code that will run only after the
		    // entire view has been rendered
		    $(this.$el).on('click', "img", (e) => {
		        console.log(e.target.src)
		    })
		 })
	},
//$nextTick dom更新 nextTick資料更新
//this.$refs.article 繫結任意物件

12. vue中指令的用法

 <input v-local-test />   

directives:{
        'local-test':function(el,binding,vnode){
            /** el可以獲取當前dom節點,並且進行編譯,也可以操作事件 **/
            /** binding指的是一個物件,一般不用 **/
            /** vnode 是 Vue 編譯生成的虛擬節點 **/
            el.style.border="1px solid red";  //操作style所有樣式
            console.log(el.value);  //獲取v-model的值
            console.log(el.dataset.name) //data-name繫結的值,需要el.dataset來獲取
            console.log(vnode.context.$route); //獲取當前路由資訊
        }
 },

13.onpopstate檢測歷史變化pushState的的的的的的的設定歷史記錄replaceState更改歷史記錄

讓對方手機不能返回 超暴力!
window.onpopstate = function(event) {
	history.pushState({page: 3}, "title 3", "?page=3");
  alert("location: " + document.location + ", state: " + JSON.stringify(event.state));
};
//繫結事件處理函式. 
history.pushState({page: 1}, "title 1", "?page=1");    //新增並激活一個歷史記錄條目 http://example.com/example.html?page=1,條目索引為1
history.pushState({page: 2}, "title 2", "?page=2");    //新增並激活一個歷史記錄條目 http://example.com/example.html?page=2,條目索引為2
//history.replaceState({page: 2}, "title 3", "?page=3"); //修改當前啟用的歷史記錄條目 http://ex..?page=2 變為 http://ex..?page=3,條目索引為3
//console.log(history)
//history.back()
//history.go(1)
//history.back(); // 彈出 "location: http://example.com/example.html?page=1, state: {"page":1}"
//history.back(); // 彈出 "location: http://example.com/example.html, state: null
//history.go(2);  // 彈出 "location: http://example.com/example.html?page=3, state: {"page":3}

14.只有標籤才能為一個表單但是標籤並不能使選擇出現下拉,標籤,輸入等單標籤不能:之前的類

15.Vue繫結事件物件用$ event @ click =“fun($ event)”

16.原生AJAX

var ajax=null;
try {
    ajax=new XMLHttpRequest()
}catch(e) {
    ajax=new ActiveXObject("Microsoft.XMLHTTP")
}
ajax.open("post","a.php",true)
//原生ajax要設定請求頭 不然預設text/plain請求頭 無法傳送鍵值對資料
ajax.setRequestHeader("content-type","application/x-www-form-urlencoded")
//請求體鍵值對資料
ajax.send("name=張三&age=20")
ajax.onreadystatechange=function(){
    if(ajax.readyState==4){
        if(ajax.status==200){
            console.log(ajax.responseText)
        }
    }else{
        console.log(ajax.status)
    }
}

17.要想在形式提交時不跳到其他頁面可以這樣!表單提交好像沒用到的XMLHttpRequest的的因為在控制檯XHR請求裡面看不到

<!-- 空iframe,用於協助處理form提交後不進行頁面跳轉的問題 -->
<form target="iframe_display" action=""></form>
<iframe  name="iframe_display" style="display: none;"></iframe>

18.拼接物件用Object.assign({},{})取物件的值Object.values()取物件的鍵Object.keys() 

19.js有幾種基本資料型別?用的typeof運算運算去檢測的話有基本型別(數字,未定義的,字串,布林)引用型別(物件,函式)

陣列是物件,空是物體另外還用日期物件正則物件等等

20.用vue時可以先繫結個原生類名在繫結個vue類名<div class =“text-danger”:class =“'active'”>

21.if判斷中undefined,null,0 NaN,“”,false都執行不了

22.Boolean(arr)用來判斷布林值是真還是假

23.iframe獲取父頁面parent.document操作父方法parent.function(),window.open()開啟的視窗可以通過opener.document opener.function()來搞

24.普通函式和定時器中的這是視窗,建構函式中的這是例項物件,原型方法中的這也是例項物件

25.當css定位設定的是絕時離脫離文件流,margin不再生效

26.在3d變換中,如果perspective不生效那可能是不相容加上-webkit-字首試驗,transform-style:perserve-3d開啟3d模式

27.回撥函式函式作為引數呼叫

28.阻止事件冒泡 e.stopPropagation