這篇文章主要介紹“分享Vue的一些小技巧”,在日常操作中,相信很多人在分享Vue的一些小技巧問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”分享Vue的一些小技巧”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
組件style的scoped
Vue 數(shù)組/對象更新 視圖不更新
vue filters 過濾器的使用
列表渲染相關(guān)
深度watch與watch立即觸發(fā)回調(diào)
這些情況下不要使用箭頭函數(shù)
路由懶加載寫法
路由的項目啟動頁和404頁面
Vue調(diào)試神器:vue-devtools
組件style的scoped:
問題:在組件中用js動態(tài)創(chuàng)建的dom,添加樣式不生效。
場景:
let a=document.querySelector('.test');
let newDom=document.createElement("div"); // 創(chuàng)建dom
newDom.setAttribute("class","testAdd" ); // 添加樣式
a.appendChild(newDom); // 插入dom
.test{
background:blue;
height:100px;
width:100px;
}
.testAdd{
background:red;
height:100px;
width:100px;
}
結(jié)果:
// test生效 testAdd 不生效
.test[data-v-1b971ada]{ // 注意data-v-1b971ada
background:blue;
height:100px;
width:100px;
}
原因:
當