對于refresh刷新太頻繁,使用防抖操作
debounce (func,delay=100){
let timer = null;
return function(...args) {
if(timer) clearTimeout(timer)
timer = setTimeout(() => {
func.apply(this,args)
},delay)
}
}
// 使用防抖請求
const pullLoadMore = debounce(this.$refs.scroll.refresh, 50)
this.$bus.$on('imageLoad',() => {
pullLoadMore()
})
每次圖片加載完成都會調(diào)用pullLoadMore函數(shù),相當(dāng)于調(diào)用function(...args) {這個匿名函數(shù),然后每次清除定時器,創(chuàng)建新的延遲定時器,直到超過這個延遲,在這個延遲期間中沒有重置定時器,就執(zhí)行func函數(shù),
所有的組件對象都有一個屬性:$el 用于獲取組件中的元素
保留滾動的位置用
activated() {
},
deactivated() {
},
方法
ES6創(chuàng)建對象
export class person {
constructor(name,age,height) {
this.name = name
this.age = age
this.height = height
}
}
使用:
const p = new person("sl",18,100)
判斷是否是空數(shù)組
Object.keys(p).length == 0
帶數(shù)據(jù)的判斷是
v-if="Object.keys(titles).length != 0"
this.$nextTick和updated()函數(shù)進(jìn)行dom加載之后的獲取高度位置、
updated() 調(diào)用會比較頻繁