uniapp 下拉刷新

1.在pages.json中对应页面开启下拉刷新

"enablePullDownRefresh": true,

2.页面中通过onPullDownRefresh监听下拉刷新

onPullDownRefresh(){
			console.log("下拉刷新-------");
		},

3.监听到下拉刷新后,将pageNum等参数置为初始化状态,并发起首次请求

		onPullDownRefresh(){
			this.params.pagenum = 1;
			this.goodsList = [];
			this.getGoodsList();
		},

4.通过标识判断是否是在下拉刷新时发起请求,是则需要关闭下拉刷新状态

		onPullDownRefresh(){
			this.params.pagenum = 1;
			this.goodsList = [];
			this.getGoodsList(true);
		},
		methods: {
			async getGoodsList(isPullDownRefresh=false) {
				const {
					list
				} = await unifyRequest(getGoodsList, this.params);
				
				this.goodsList = [...this.goodsList,...list.goods];
				this.total = list.total;
				
				if(isPullDownRefresh) uni.stopPullDownRefresh();
			}
		}

你可能感兴趣的:(微信小程序,uniapp,前端,uni-app)