1 | <template>
|
2 | <div class="container">
|
3 | <div v-if="hasmore">
|
4 | <img v-if="loading" :src="icon" width="16" class="icon" />
|
5 | <div v-else class="loading" @click="getdata">
|
6 | <span class="name">{{ text }}</span>
|
7 | </div>
|
8 | </div>
|
9 | <div v-else class="loading">没有更多数据了</div>
|
10 | </div>
|
11 | </template>
|
12 | <script>
|
13 | import icon from "../assets/images/loading2.gif";
|
14 | import http from "@script/http";
|
15 | import getUrlParams from "ynw/getUrlParams";
|
16 | /**
|
17 | * ----------------------------------------
|
18 | * 加载数据
|
19 | * @param {String} url
|
20 | * @param {Function} data
|
21 | * ----------------------------------------
|
22 | */
|
23 | export default {
|
24 | props: {
|
25 | url: String,
|
26 | },
|
27 | data() {
|
28 | return {
|
29 | icon,
|
30 | hasmore: true,
|
31 | loading: false,
|
32 | rows: [],
|
33 | };
|
34 | },
|
35 | computed: {
|
36 | text() {
|
37 | return this.loading ? "正在加载" : "加载更多";
|
38 | },
|
39 | },
|
40 | mounted() {
|
41 | this.getdata();
|
42 | },
|
43 | methods: {
|
44 | async getdata() {
|
45 | const len = this.rows.length;
|
46 |
|
47 | const urlParams = getUrlParams(window.location.href);
|
48 | const params = { ...urlParams };
|
49 | if (len > 0) {
|
50 | params.last = this.rows[len - 1]._id;
|
51 | }
|
52 | this.loading = true;
|
53 | let res = await http.get(this.url, { params });
|
54 | this.loading = false;
|
55 | this.rows = this.rows.concat(res);
|
56 | this.hasmore = res.length === 10;
|
57 | this.$emit("data", this.rows);
|
58 | },
|
59 | },
|
60 | };
|
61 | </script>
|
62 | <style scoped lang="scss">
|
63 | .container {
|
64 | padding: 10px 0;
|
65 | text-align: center;
|
66 | overflow: hidden;
|
67 | height: 40px;
|
68 | }
|
69 | .loading {
|
70 | text-align: center;
|
71 | padding: 10px;
|
72 | font-size: 13px;
|
73 | color: gray;
|
74 | }
|
75 | .icon {
|
76 | position: relative;
|
77 | top: 4px;
|
78 | margin-right: 3px;
|
79 | }
|
80 | </style>
|