-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathListPage.vue
89 lines (87 loc) · 2.39 KB
/
ListPage.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<template>
<div class="ListPage" v-if="show">
<van-list
ref="list"
@load="load"
:immediate-check="false"
v-model="loading"
:finished="finished"
:finished-text="finishedText"
>
<slot :list="list"></slot>
</van-list>
</div>
</template>
<script>
export default {
name: "ListPage",
props:{
apiPath:{type:Function,default:Function},
params:{type:Object,default:()=>({})},
finishedText:{type:String,default:"没有更多了"},
},
data() {
return {
list: [],
loading: false,
finished: false,
pageNo:1,
pageSize:10,
no_page:false,
show:true,
};
},
methods:{
load(){
const formData = {
pageNo:this.pageNo,
pageSize:this.pageSize,
no_page:this.no_page,
...this.params,
}
this.apiPath(formData).then(res=>{
if(formData.no_page){
this.list = res.data;
this.loading = false;
this.finished = true;
}else {
if(formData.pageNo === 1){
this.list = res.data.list
}else {
this.list = this.list.concat(res.data.list);
}
if(this.list.length >= res.data.total){
this.finished = true;
}
this.pageNo += 1;
this.loading = false;
}
this.$emit("dataChange",res, formData);
}).catch((err)=>{
this.loading = false;
this.finished = true;
this.$emit("dataChangeError",err, formData);
})
},
init(){
this.list = [];
this.pageNo = 1;
this.pageSize = 10;
this.no_page = false;
this.loading = false;
this.finished = false;
this.show = false;
this.$nextTick(()=>{
this.show = true;
setTimeout(()=>{
this.$refs.list.check()
},500)
})
}
}
}
</script>
<style scoped lang="less">
.ListPage{
}
</style>