1. 程式人生 > 實用技巧 >Vant中List列表下拉載入更多

Vant中List列表下拉載入更多

van-list上只有一層父級元素div,多了可能下拉加載出不來;或者更多

<template>
    <div class="scholl-declarepage">
	
        <van-list
            v-model="loading"
            :finished="finished"
            finished-text="沒有更多了"
            @load="onLoad"
            :immediate-check="cheack"
            >
			
                <swipe-cell
                custom
                class="bootom-having-border"
                :isEdit="isEdit"
                v-for="(item,index) in listAchool" :key="index"
                @edit="detior(item)"
                @remove="delItem(item)"
                >
                    <scholl-list-com :listObj="item" @gotodetails="gotodetails(item)"></scholl-list-com>
                </swipe-cell>
            </van-list>  
    </div>
</template>

loading: false,
finished: false,
 cheack:true,

paramsList:{
	orgId: "",
	pageIndex: 0,
	pageSize: 10 
},
listAchool:[],


 onLoad(){
	this.paramsList.pageIndex+=1;
	 this.schoolListContApi();//列表渲染
},
			
   schoolListContApi(){
                this.paramsList.orgId=this.userInfo.orgId,
                schoolListCont(this.paramsList).then(res=>{
                    console.log(res);
                    if(res.success==true){
						
                        this.loading = false;// 這一次的載入狀態結束 
                        this.listAchool=this.listAchool.concat(res.data); 
                       
                       if(res.data.length==0 || this.listAchool.length>=res.totalDatas){
                            this.finished = true;//所有的資料已經全部載入完了
                        }else{
                            this.finished = false;
                        }
                    }else{
                        this.finished = false;
                    }
                
                })
            },	
				
				
				
 // 刪除請求
commendDelApi(item){
	let params={
		id:item.id
	}
	schoolDelCont(params).then(res=>{
		if(res.success==true){
			this.paramsList.pageIndex=1;//重新賦值
			this.listAchool=[];
			this.schoolListContApi();
		}   
	})
},