*今天做了一个瀑布流效果,把这个效果分享一下。*
瀑布流就是我们在浏览京东或者淘宝商品时,你往下面浏览商品你会发现,你浏览的商品就好像没有尽头似的,可以去京东看一下效果。
第一步绑定元素
第二步在mounted中通过scroll事件给windoww做监听
data(){
return {
islogin:false
}
},
mounted(){
this.tt =throttle(1000,this.scrolllogin.bind(this))
window.addEventListener(‘scroll’,this.tt)
},
methods:{
scrolllogin(){
if(this.islogin) return;
if(this.KaTeX parse error: Expected '}', got 'EOF' at end of input: … this.emit(‘view’)
}
}
},
因为节流问题通过throttle方法来进行优化 // throttle(间隔时间,执行的函数)
destroyed(){
window.removeEventListener(‘scroll’,this.tt)
},
因为防止之后组件被销毁时,事件依然存在的问题
第四步在父组件中操作
<waterfall ref=“waterfall” @view=‘loadingMenuHandle’>
拿到子组件的$emit自定义方法,然后绑定一个方法做操作。
loadingMenuHandle(){
this.page++
getMenus({page:this.page}).then(a=>{
this.menuList.push(...a.data.list)
this.$refs.waterfall.islogin = false;
})
}
不太会总结,谅解。