-
Notifications
You must be signed in to change notification settings - Fork 2
/
fruit-market.html
60 lines (60 loc) · 1.64 KB
/
fruit-market.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<link
rel="stylesheet"
href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"
/>
<title>水果商店</title>
</head>
<body>
<div id="app">
<!-- 列表 -->
<ul>
<li v-for="fruit in fruits" :key="fruit._id">
{{ fruit.name }} - {{ fruit.price }}
</li>
</ul>
<!-- 分页 -->
<el-pagination
layout="prev, pager, next"
@current-change="currentChange"
:total="total" page-size="4"
></el-pagination>
</div>
<script>
var app = new Vue({
el: "#app",
data: {
page: 1,
total: 0,
fruits: []
},
created() {
this.getData();
},
methods: {
currentChange(page) {
this.page = page;
this.getData();
},
getData() {
axios
.get(`/api/list?page=${this.page}`)
.then(res => res.data)
.then(({ data }) => {
this.fruits = data.fruits;
this.total = data.pagination.total;
});
}
}
});
</script>
</body>
</html>