module.exports = Behavior({ data: { loading: false, // 加载状态标志位 list: [], grade: '', pageNo: 1, totalSize: 0, noMoreData: false, // 无更多数据置为 false }, properties: { pageSize: { type: Number, value: 10 } }, methods: { async getData(fn, args) { if (this.data.noMoreData) { return } let params = { pageNo: this.data.pageNo, pageSize: this.properties.pageSize, ...args } // 加载状态,用于页面中控制加载动画的显示 this.setData({ loading: true }) let { list, totalSize } = await fn(params).finally(() => { // 页面渲染完成后关闭加载动画字段 wx.nextTick(() => { this.setData({ loading: false }) }); }) list = [...this.data.list, ...list] console.log(list, totalSize); this.setData({ pageNo: ++this.data.pageNo, list, totalSize, noMoreData: list.length >= totalSize }) }, resetData() { console.log("触发resetData"); if (this.data.loading) return; // 如果接口已经在请求中,则不重置数据,防止用户持续下拉刷新 this.setData({ loading: false, list: [], pageNo: 1, totalSize: 0, noMoreData: false, }) this.loadMore(); // 调用页面中的接口请求方法 }, }, })