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

vue 實(shí)現(xiàn)滾動到底部翻頁效果(pc端)

 更新時間:2019年07月31日 11:26:34   作者:小角色Byme  
這篇文章主要介紹了pc端vue 滾動到底部翻頁效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值 ,需要的朋友可以參考下

pc端vue 滾動到底部翻頁 效果,具體內(nèi)容如下所示:

html:

<div class="list" ref="scrollTopList">
                <div class="listsmall" v-for="(item,index) of list" :key="index" @click="getDeviceInfo(item.id)">
                  <span class="state" :class="{'state1':item.status==1,'state0':item.status==0,'state2':item.status==2,'state3':item.status==3}"></span>
                  <span class="text textcolor">【{{item.code||item.name}}】</span>
                  <span class="text">{{item.name}}</span>
                </div>
              </div>

js:

先寫滾動事件

handleScroll(){
        let scrollTop = this.$refs.scrollTopList.scrollTop, 
        clientHeight = this.$refs.scrollTopList.clientHeight, 
        scrollHeight = this.$refs.scrollTopList.scrollHeight,
        height = 50; //根據(jù)項(xiàng)目實(shí)際定義
        if(scrollTop +clientHeight >= scrollHeight - height){
          if(this.pageSize > this.total){
            return false
          }else{
            this.pageSize = this.pageSize +10 //顯示條數(shù)新增
            this.getpageList() //請求列表list 接口方法
          } 
        }else{
          return false
        }
      },

method中寫節(jié)流函數(shù)

throttle(func, wait) {
        let lastTime = null
        let timeout
        return () => {
          let context = this;
          let now = new Date();
          let arg = arguments;
          if (now - lastTime - wait > 0) {
            if (timeout) {
              clearTimeout(timeout)
              timeout = null
            }
            func.apply(context, arg)
            lastTime = now
          } else if (!timeout) {
            timeout = setTimeout(() => {
              func.apply(context, arg)
            }, wait)
          }
        }
      },

mounted中調(diào)用

mounted(){
this.$refs.scrollTopList.addEventListener("scroll",this.throttle(this.handleScroll,500),true)
},

//-------------------------------------------------------------------------------------------第二種寫法

html:

添加滾動事件

<div class="tablelist-box" @scroll="scrollEvent($event)">
        <div
         class="tablelist"
         :class="{'active':listDevicesDetailIndex==index}"
         v-for="(item,index) of deviceList"
         :key="index"
         v-if="deviceList.length !== 0"
         @click="deviceDetail(item,index)"
        >
         <span class="tablelist-status">
          <i
           :class="{zx:item.status==1,lx:item.status==2, wjh:item.status==0,gj:item.status==3}"
          ></i>
         </span>
         <span class="tablelist-bg">{{item.code != null ?item.code:"/"}}</span>
        </div>
        <div class="list-more" v-show="!deviceListIsFinish">{{deviceTip}}</div>
        <div class="list-more" v-show="deviceListIsFinish">{{deviceTip}}</div>
       </div>

 css:

tablelist-box{
 height: //根據(jù)實(shí)際項(xiàng)目取
 overflow:auto //必須 不然判斷有問題
}

css 定義

js

寫入滾動事件

scrollEvent(e) {
   if (e instanceof Event) {
    let el = e.target;
    let scrollTop = el.scrollTop;
    // 獲取可視區(qū)的高度
    let clientHeight = el.clientHeight;
    // 獲取滾動條的總高度
    let scrollHeight = el.scrollHeight;
    let height = 50;
    //到底了
    // console.log(this.deviceListIsLoad, this.deviceListIsFinish);
    // console.log(scrollTop, clientHeight, scrollHeight);
    //是否繼續(xù)加載且已完成加載
    if (
     scrollTop + clientHeight >= scrollHeight &&
     this.deviceListIsLoad &&
     !this.deviceListIsFinish
    ) {
     // 把距離頂部的距離加上可視區(qū)域的高度 等于或者大于滾動條的總高度就是到達(dá)底部
     this.deviceListIsLoad = true;
     console.log("到底了");
     setTimeout(() => {
      this._deviceListPage();
     }, 1000);
    }
   }

請求列表的處理

 _deviceListPage() {
   let params = {
    pageSize: this.devicePageSize,
    pageNum: this.devicePageNum,
    kw: "", //查詢條件(通配查詢條件)
    type: this.deviceType, //設(shè)備類型(下拉)2.1.6接口獲取
    code: this.deviceCode, //設(shè)備編號
    areaId: this.deviceareaId, //位置區(qū)域
    status: this.deviceStatus, //狀態(tài) 1:在線(正常),0:未激活,2已離線,3.告警
    imei: "" //imei編號
   };
   deviceListPage(params).then(res => {
    if (res.code == 200) {
     this.devicePageTotal = res.body.total;
     this.devicePageSize = res.body.pageSize;
     this.devicePageNum = res.body.pageNum;
     this.devicePageTotalPages = parseInt(
      (this.devicePageTotal + this.devicePageSize - 1) /
       this.devicePageSize
     );
     if (this.devicePageTotal == 0) {
      // console.log("沒有數(shù)據(jù)");
      //沒有數(shù)據(jù)
      this.deviceListnodata = true;
      this.deviceListIsLoad = false;
      this.deviceListIsFinish = true;
      this.devicePageNum = 1;
      this.deviceTip = "暫無數(shù)據(jù)";
      return false;
     }
     this.deviceList = this.deviceList.concat(res.body.datas);
     // console.log(this.devicePageNum, this.devicePageTotalPages);
     if (this.devicePageNum == this.devicePageTotalPages) {
      //沒有更多
      this.deviceListIsLoad = false;
      this.deviceListIsFinish = true;
      this.devicePageNum = 1;
      this.deviceTip = "沒有更多了~";
      // console.log("沒有更多了");
     } else {
      // console.log("下一頁");
      //下一頁
      this.deviceListIsLoad = true;
      this.deviceListIsFinish = false;
      this.devicePageNum++;
      this.deviceTip = "正在加載中~";
     }
     // console.log("deviceList", this.deviceList);
    } else {
     // this.deviceList = [];
     this.deviceListIsLoad = false;
     this.deviceListIsFinish = true;
     this.devicePageNum = 1;
     this.deviceTip = "數(shù)據(jù)加載失敗~";
    }
   });
  },

return中的定義

devicePageSize: 10, //每頁顯示
   devicePageNum: 1, //當(dāng)前頁
   devicePageTotal: 0, //總條數(shù)
   devicePageTotalPages: 0, //總頁數(shù)
   deviceListIsFinish: false, //是否加載完成
   deviceListIsLoad: false, //是否加載更多
   deviceListnodata: false, //是否有數(shù)據(jù)
   deviceTip: "",

總結(jié)

以上所述是小編給大家介紹的vue 實(shí)現(xiàn)滾動到底部翻頁效果(pc端),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • Vue2.x-使用防抖以及節(jié)流的示例

    Vue2.x-使用防抖以及節(jié)流的示例

    這篇文章主要介紹了Vue2.x-使用防抖以及節(jié)流的示例,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下
    2021-03-03
  • vue實(shí)現(xiàn)旋轉(zhuǎn)木馬動畫

    vue實(shí)現(xiàn)旋轉(zhuǎn)木馬動畫

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)旋轉(zhuǎn)木馬動畫,圖片數(shù)量無限制,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • JointJS流程圖的繪制方法

    JointJS流程圖的繪制方法

    這篇文章主要為大家介紹了JointJS流程圖的繪制方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • vue中實(shí)現(xiàn)一個項(xiàng)目里兼容移動端和pc端

    vue中實(shí)現(xiàn)一個項(xiàng)目里兼容移動端和pc端

    這篇文章主要介紹了vue中實(shí)現(xiàn)一個項(xiàng)目里兼容移動端和pc端問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • vue2.x中keep-alive源碼解析(實(shí)例代碼)

    vue2.x中keep-alive源碼解析(實(shí)例代碼)

    Keep-Alive模式避免頻繁創(chuàng)建、銷毀鏈接,允許多個請求和響應(yīng)使用同一個HTTP鏈接,這篇文章主要介紹了vue2.x中keep-alive源碼解析,需要的朋友可以參考下
    2023-02-02
  • Electron-vue腳手架改造vue項(xiàng)目的方法

    Electron-vue腳手架改造vue項(xiàng)目的方法

    這篇文章主要介紹了Electron-vue腳手架改造vue項(xiàng)目的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-10-10
  • vue中el-table兩個表尾合計(jì)行聯(lián)動同步滾動條實(shí)例代碼

    vue中el-table兩個表尾合計(jì)行聯(lián)動同步滾動條實(shí)例代碼

    項(xiàng)目開發(fā)中遇到一個比較兩個form差異的需求,但當(dāng)item過多就需要滾動條,下面這篇文章主要給大家介紹了關(guān)于vue中el-table兩個表尾合計(jì)行聯(lián)動同步滾動條的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • 如何區(qū)分vue中的v-show 與 v-if

    如何區(qū)分vue中的v-show 與 v-if

    這篇文章主要介紹了如何區(qū)分vue中的v-show 與 v-if ,幫助大家更好的理解和學(xué)習(xí)vue框架,感興趣的朋友可以了解下
    2020-09-09
  • Vue-router中hash模式與history模式的區(qū)別詳解

    Vue-router中hash模式與history模式的區(qū)別詳解

    這篇文章主要給大家介紹了關(guān)于Vue-router中hash模式與history模式區(qū)別的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • vue?同局域網(wǎng)訪問不到的問題及解決

    vue?同局域網(wǎng)訪問不到的問題及解決

    這篇文章主要介紹了vue?同局域網(wǎng)訪問不到的問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10

最新評論

潞城市| 长寿区| 宝清县| 廉江市| 麻栗坡县| 阿荣旗| 铁岭县| 长治县| 通渭县| 北辰区| 武胜县| 八宿县| 普定县| 洪洞县| 大宁县| 龙川县| 涿州市| 吉水县| 板桥市| 莎车县| 安多县| 绵阳市| 延津县| 寿光市| 通城县| 大关县| 河南省| 保康县| 彰武县| 玉山县| 滕州市| 曲麻莱县| 汾西县| 耒阳市| 合阳县| 迁西县| 马鞍山市| 松原市| 凤冈县| 宣武区| 万安县|