data() {
return {
page: 1,
pageSize: 10,
total: 0,
projectList: [],
isloading: false
}
}
methods: {
async getProjectList(cb) {
// 打开节流阀
this.isloading = true
// 请求数据
const { data: res } = await uni.$http.get('/api/projectlist')
// 关闭节流阀
this.isloading = false
cb && cb()
if (res.status !== 200) return uni._showToast(res.message)
this.projectList = [...this.projectList, ...res.data]
this.total = res.total
}
},
onPullDownRefresh() {
// 重置关键数据
this.page = 1
this.total = 0
this.isloading = false
this.projectList = []
this.getProjectList(() => uni.stopPullDownRefresh())
},
onReachBottom() {
// 判断是否还有下一页数据
if(this.page * this.pageSize >= this.total) return uni._showToast('数据加载完毕!')
// 判断是否正在请求其他数据,如果是则不发起额外的请求
if(this.isloading) return
this.page = this.page + 1
this.getProjectList()
}