Vue中使用VantUI的list组件下拉刷新及上拉加载功能

template


    
        
    

JS

 data() {
    return {
        list: [],
        loading: false,
        finished: false,
        refreshing: false,
        page:1
    };
},
created(){
   this.getRechargeLog()
},
methods: {
        async getRechargeLog(isRefresh){
            const {data:{list}} = await rechargeLog(this.page)
            console.log('充值记录:',list)

            //拼接列表数据
            if(isRefresh){//下拉刷新
                this.list = [...list.data,...this.list]
                this.refreshing = false;
            }else{//上拉加载
                this.list = [...this.list,...list.data]
                this.loading = false;
            }
            if(list.data.length==0){
                this.finished = true;
            }

            console.log('接口请求出来的账单列表:',list)
        },
        onLoad() {
            this.page++
            this.getRechargeLog()
        },
        onRefresh() {//刷新事件
            console.log('刷新事件')
            this.getRechargeLog(true)
        },
},

效果:(#^.^#)

Vue中使用VantUI的list组件下拉刷新及上拉加载功能_第1张图片Vue中使用VantUI的list组件下拉刷新及上拉加载功能_第2张图片

你可能感兴趣的:(Vue,vue.js,list,windows)