HtLoadData.vue
1.57 KB
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
<template>
<div style="display:none" v-loading.fullscreen.lock="fullscreenLoading">加载数据...</div>
</template>
<script>
import req from "@/request.js";
export default {
name: "ht-load-data",
props: {
url: {
type: String,
default: ""
},
requestMethod: {
type: String,
default: "GET"
},
context: {
type: String,
default: ""
},
isPagination:{
type:Boolean,
default:true
}
},
data() {
return {
fullscreenLoading: false
};
},
watch: {
url: {
handler: function(newVal, oldValue) {
if (newVal) {
this.getData();
}
},
immediate: true
}
},
mounted() {},
methods: {
async getData() {
this.fullscreenLoading = true;
let response = await req
.request({
url: `${window.context[this.context]}`+this.url,
method: this.requestMethod,
data:this.isPagination ? {} :{
pageBean: {
page: 1,
pageSize: -1,
showTotal: true
},
}
})
.finally(() => {
this.fullscreenLoading = false;
});
this.$emit("update:url","");
this.$emit("after-load-data", response.data);
},
async loadData(url){
this.fullscreenLoading = true;
let response = await req
.request({
url: url,
method: this.requestMethod
})
.finally(() => {
this.fullscreenLoading = false;
});
return response.data;
}
}
};
</script>