最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue組件實現(xiàn)觸底判斷

 更新時間:2019年06月26日 11:26:01   作者:Sallywa  
這篇文章主要為大家詳細介紹了Vue組件實現(xiàn)觸底判斷,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Vue組件實現(xiàn)觸底判斷的具體代碼,供大家參考,具體內容如下

非常簡陋的代碼,以后有空回來完善

子組件代碼:

<template>
 <div class="scroll"></div>
</template>
 
<script>
 export default {
 name:'Scroll',
 methods:{
 scrollEvent(){
 if (document.documentElement.scrollTop
      + document.documentElement.clientHeight 
     >= document.body.scrollHeight) {
  this.onBottom();
 }
 }
 },
 props:{
 onBottom:Function
 },
 mounted(){
 window.addEventListener('scroll', this.scrollEvent,false);
 },
 destroyed () {
   window.removeEventListener('scroll', this.scrollEvent,false);
  }
 }
</script>

document.documentElement.scrollTop + document.documentElement.clientHeight >= document.body.scrollHeightb表示已經到頁面底部了,那么就觸發(fā)函數(shù)onBottom,函數(shù)onBottom是父組件傳遞過來的用于回調的函數(shù) 

父組件代碼:

把子組件scroll放在父組件的底部(切記,不然函數(shù)不起作用),用作觸底判斷。

<template>
 <div class="wrap">
 <scroll :onBottom = "onBottom"></scroll>
 </div>
</template>
 
<script>
 import Scroll from '@/components/scroll'
 export default {
 name: 'roll',
 components:{
 Scroll,
 },
 methods:{
 onBottom(){
  console.log('bottom')
 }
 }
 }
</script>
<style type="text/css" lang="stylus" scoped>
 .wrap{
 height: 1000px;
 background: grey;
 width: 100%;
 }
</style> 

父子傳值也可以傳遞data里面的函數(shù)。這里我的回調函數(shù)里面進行的操作是到底部后console出bottom

效果:

可以看到觸發(fā)頻次比較高,其實子組件里面應該加一個函數(shù)節(jié)流函數(shù),限制觸發(fā)頻率。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

建水县| 夏河县| 喜德县| 灵台县| 犍为县| 镇江市| 礼泉县| 鹤山市| 收藏| 巴东县| 方正县| 田东县| 达尔| 通州市| 新化县| 靖边县| 额尔古纳市| 青河县| 阿城市| 临朐县| 聂荣县| 鄯善县| 乌鲁木齐市| 玉山县| 阳信县| 荥阳市| 招远市| 丰宁| 德保县| 绍兴县| 宁武县| 东城区| 噶尔县| 高淳县| 石景山区| 阜城县| 两当县| 醴陵市| 明水县| 墨玉县| 米泉市|