uniapp之uview上拉加载和下拉刷新

  1. onLoad中需要调用getList()
  2. tab切换需要初始化data,然后调用getList()
  3. 开启下拉刷新需要在json文件配置
		<view class="mg-30">
			<empty v-if="list.length==0" text="暂无订单"></empty>
			<orderItem :type="1" :item="item" v-for="(item,i) in list" :key="i" class="mb-30"></orderItem>
			<u-loadmore v-show="list.length>9" :status="status" icon-type="flower" bg-color="transperant"   margin-top="30" margin-bottom="30"/>
		</view>
				page:1,
				status: 'loadmore',
				list:[],
//下拉
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			this.getList()
		},
//下拉
	onReachBottom() {
			//避免多次触发
			if (this.status == 'loading' || this.status == 'nomore') {
				return;
			}
			this.getList()
		},

//接口
			getList(){
				this.status = "loading";
				this.$http('/addons/ddrive/order/takingList',{
					page:this.page,
					city:this.city
				},"POST").then(data=>{
					if (data.length < 10) {
						this.status = "nomore"
					} else {
						this.page = this.page + 1
						this.status = "loadmore"
					}
					this.list = this.list.concat(data)
					uni.stopPullDownRefresh();
				})
			},

你可能感兴趣的:(uniapp)