vant 瀑布流滾動(dòng)加載(搜索時(shí)onload不觸發(fā)無法實(shí)現(xiàn)滾動(dòng)加載)

參考文章地址:https://blog.csdn.net/zjKnows/article/details/103911281

一、需求以及問題:

需求:最近做了一個(gè)手機(jī)端頁面 一個(gè)列表頁面需要實(shí)現(xiàn)瀑布流滾動(dòng)加載(并且列表的最上邊還有一個(gè)搜索功能);
問題:用vant-ui 的vant-list實(shí)現(xiàn)了瀑布流滾動(dòng)加載,但是列表上邊的搜索功能如果搜索出來的數(shù)據(jù)多的話無法顯示 瀑布流滾動(dòng)加載

如圖:
微信截圖_20200403152126.png

二、實(shí)現(xiàn)代碼

 <div id="app" >
     <van-search v-model="keyWord" placeholder="請(qǐng)輸入搜索關(guān)鍵詞" @search="searchHandle"></van-search>
        <van-list
 v-model="loading"
 :finished="finished"
 finished-text="沒有更多了"
 @load="loadingData"
>
 <van-cell v-for="item in fitStoreList" :key="item.StoreId" :title="item.StoreName"></van-cell>
 <div v-if="fitStoreList.length==0" class="noData">暫無數(shù)據(jù)</div>
   </div>
<script>
new Vue({
         el: '#app',
         data: function() {
           return { 
               fitStoreList: [],
               loading: false,//vant-ui框架里必須的
               finished: false,//vant-ui框架里必須的
               pageNumber:0,//第幾頁
               pageSize:10,//每頁顯示的條數(shù)
               keyWord:""http://搜索綁定的字段

           }
         },
         watch: {
           // 監(jiān)聽 keyWord 如果keyWord 發(fā)生變化 那么需要重置數(shù)據(jù),此處很重要
           keyWord(newName, oldName) {
                 this.pageNumber=0;
                 this.pageSize=10;
                 this.fitStoreList=[]
             }
         },
methods: {
        //搜索 這個(gè)是實(shí)現(xiàn)搜索數(shù)據(jù)后瀑布流滾動(dòng)加載的關(guān)鍵
           searchHandle(){
             this.loading = true;//下拉加載中
             this.finished = false;//下拉結(jié)束
             if(this.loading){
                 this.loadingData();
             }
           },
         loadingData(){
             this.pageNumber++;
             var postData = {//列表數(shù)據(jù)接口的傳參
                 "Id": , 
                 "PageNumber":this.pageNumber,
                  "PageSize":this.pageSize,
                  "KeyWord":this.keyWord 
            };
           this.$http.post(
               "/test/testlist",//接口地址
               postData,
               { emulateJSON: true }
           ).then(function (response) {
               if(response.data.IsSuccess){
                 this.loading = false;//數(shù)據(jù)請(qǐng)求回來后要關(guān)閉loading
                   if(response.data.Data.length!=0){
//如果請(qǐng)求出來有數(shù)據(jù)就把請(qǐng)求回來的數(shù)據(jù)合并到當(dāng)前的 fitStoreList里
                       this.fitStoreList=this.fitStoreList.concat(response.data.Data)
                    }else{
                      //如果請(qǐng)求回來的沒有數(shù)據(jù)了那么就不再請(qǐng)求接口
                      this.finished = true;
                    }
               }else{
                   this.fitStoreList=[]
               }
              
           }, function (err) {
           });
          }
}
})
</script>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容