木邻有你前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
1.2 KiB

// 简化版列表的混入
export default {
data() {
return {
list: [],
params: {
pageNo : 1,
pageSize : 10,
},
mixinListApi: '',
isLoading: false
}
},
methods: {
initData() {
this.list = []
this.params.pageNo = 1
this.params.pageSize = 10
},
async getList() {
this.isLoading = true
if (!this.$api[this.mixinListApi]) {
console.log('mixinApi不存在', this.mixinListApi);
return
}
const res = await this.$api[this.mixinListApi]({
...this.params
})
if (res.code === 200 && res.result.record.length) {
this.list = [...this.list, ...res.result.record]
this.params.pageNo++
}else {
uni.showToast({
title: '暂无数据',
icon: 'none'
})
}
// 如果有在加载中
if (this.isLoading) {
this.isLoading = false
}
// 有过有在下拉加载
uni.stopPullDownRefresh()
},
},
async onShow() {
await this.getList()
},
onHide() {
this.initData()
},
async onPullDownRefresh() {
this.initData()
await this.getList()
},
async onReachBottom() {
await this.getList()
}
}