欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

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

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

創(chuàng)新互聯(lián)是專(zhuān)業(yè)的赤城網(wǎng)站建設(shè)公司,赤城接單;提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行赤城網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lá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:

先寫(xiě)滾動(dòng)事件

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() //請(qǐng)求列表list 接口方法
          } 
        }else{
          return false
        }
      },

method中寫(xiě)節(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)
},

//-------------------------------------------------------------------------------------------第二種寫(xiě)法

html:

添加滾動(dòng)事件

<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 //必須 不然判斷有問(wèn)題
}

css 定義

js

寫(xiě)入滾動(dòng)事件

scrollEvent(e) {
   if (e instanceof Event) {
    let el = e.target;
    let scrollTop = el.scrollTop;
    // 獲取可視區(qū)的高度
    let clientHeight = el.clientHeight;
    // 獲取滾動(dòng)條的總高度
    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òng)條的總高度就是到達(dá)底部
     this.deviceListIsLoad = true;
     console.log("到底了");
     setTimeout(() => {
      this._deviceListPage();
     }, 1000);
    }
   }

請(qǐng)求列表的處理

 _deviceListPage() {
   let params = {
    pageSize: this.devicePageSize,
    pageNum: this.devicePageNum,
    kw: "", //查詢條件(通配查詢條件)
    type: this.deviceType, //設(shè)備類(lèi)型(下拉)2.1.6接口獲取
    code: this.deviceCode, //設(shè)備編號(hào)
    areaId: this.deviceareaId, //位置區(qū)域
    status: this.deviceStatus, //狀態(tài) 1:在線(正常),0:未激活,2已離線,3.告警
    imei: "" //imei編號(hào)
   };
   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("沒(méi)有數(shù)據(jù)");
      //沒(méi)有數(shù)據(jù)
      this.deviceListnodata = true;
      this.deviceListIsLoad = false;
      this.deviceListIsFinish = true;
      this.devicePageNum = 1;
      this.deviceTip = "暫無(wú)數(shù)據(jù)";
      return false;
     }
     this.deviceList = this.deviceList.concat(res.body.datas);
     // console.log(this.devicePageNum, this.devicePageTotalPages);
     if (this.devicePageNum == this.devicePageTotalPages) {
      //沒(méi)有更多
      this.deviceListIsLoad = false;
      this.deviceListIsFinish = true;
      this.devicePageNum = 1;
      this.deviceTip = "沒(méi)有更多了~";
      // console.log("沒(méi)有更多了");
     } else {
      // console.log("下一頁(yè)");
      //下一頁(yè)
      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, //每頁(yè)顯示
   devicePageNum: 1, //當(dāng)前頁(yè)
   devicePageTotal: 0, //總條數(shù)
   devicePageTotalPages: 0, //總頁(yè)數(shù)
   deviceListIsFinish: false, //是否加載完成
   deviceListIsLoad: false, //是否加載更多
   deviceListnodata: false, //是否有數(shù)據(jù)
   deviceTip: "",

總結(jié)

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

新聞名稱:vue實(shí)現(xiàn)滾動(dòng)到底部翻頁(yè)效果(pc端)
轉(zhuǎn)載來(lái)于:http://chinadenli.net/article42/pgjgec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序域名注冊(cè)全網(wǎng)營(yíng)銷(xiāo)推廣電子商務(wù)商城網(wǎng)站網(wǎng)站設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化