对于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()
})
每次图片加载完成都会调用pullLoadMore函数,相当于调用function(...args) {这个匿名函数,然后每次清除定时器,创建新的延迟定时器,直到超过这个延迟,在这个延迟期间中没有重置定时器,就执行func函数,
所有的组件对象都有一个属性:$el 用于获取组件中的元素
保留滚动的位置用
activated() {
},
deactivated() {
},
方法
ES6创建对象
export class person {
constructor(name,age,height) {
this.name = name
this.age = age
this.height = height
}
}
使用:
const p = new person("sl",18,100)
判断是否是空数组
Object.keys(p).length == 0
带数据的判断是
v-if="Object.keys(titles).length != 0"
this.$nextTick和updated()函数进行dom加载之后的获取高度位置、
updated() 调用会比较频繁
网友评论