-
Notifications
You must be signed in to change notification settings - Fork 0
/
路由.html
205 lines (188 loc) · 7.26 KB
/
路由.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>路由</title>
<!-- 7月02日,购物案例美化css -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<style type="text/css">
html,
body {
padding: 0;
margin: 0;
height: 100%;
}
div {
padding: 0;
margin: 0;
}
.leftlayout {
margin-top: 70px;
width: 30%;
height: 100%;
float: left;
position: absolute;
display: block;
}
ul li {
list-style: none;
}
.rightlayout {
height: 100%;
margin-left: 30%;
width: 70%;
}
.container {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="app">
<div class="container">
<div class="leftlayout">
<ul>
<li>
<router-link to="/user" style="text-decoration: none;">用户管理</router-link>
</li>
<li>
<router-link to="/good" style="text-decoration: none;">商品管理</router-link>
</li>
<!--视图占位符-->
<router-view></router-view>
</ul>
</div>
</div>
</div>
<!-- 7月02日,购物案例美化js -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/vue.js" charset="utf-8"></script>
<script type="text/javascript" src="js/vue-router.js"></script>
<script type="text/javascript">
// 定义组件
let user = {
template: `
<div class="rightlayout">
<p>用户列表</p>
</div>`
}
let good = {
props: ['abooks'],
template: `
<div class="rightlayout" style="width:1000px;">
<!-- 购物车列表 -->
<table class="table table-hover table-dark">
<thead>
<tr>
<th >序号</th>
<th >书籍名称</th>
<th >出版日期</th>
<th >价格</th>
<th >购买数量</th>
<th >操作</th>
</tr>
</thead>
<!-- 7月02日,购物车没有物品时,显示没有商品即可 -->
<!-- <tr v-if = "books.length = 0">没有商品信息!</tr> -->
<tbody>
<tr v-for ="(book,index) in abooks" :abooks='books'>
<td><input type="checkbox" :checked="book.isChecked" @click="selected(index)" :class="{active: activeName == index}"/>{{book.id}}</td>
<td>{{book.name}}</td>
<td>{{book.date}}</td>
<td >{{book.price}}</td>
<td>
<button type="button" @click = "mouse(book)" :disabled="book.number < 1">-</button>
{{book.number}}
<button type="button" @click = "add(book)">+</button>
</td>
<td>
<button type= "button" @click = "remove(index)" >移除</button>
</td>
</tr>
</tbody>
</table>
<button @function="getTotal">总价格:{{total }}</button>
</div>`
}
//定义路由对象
const router = new VueRouter({
//路由规则
routes: [{
path: '/',
redirect: '/user'
}, {
path: '/user',
component: user
}, {
path: '/good',
component: good
}]
})
let vm = new Vue({
el: '#app',
router,
data: {
books: [
// 7月01日,数组对象中的属性书籍名称必须是最后一个属性
{
isChecked: true,
id: 1,
date: '2010-10',
price: 60.00,
number: 1,
name: '《Java从入门到放弃》'
}, {
isChecked: false,
id: 2,
date: '2012-10',
price: 90.00,
number: 1,
name: '《PHP从入门到放弃》'
}, {
isChecked: false,
id: 3,
date: '2013-10',
price: 80.01,
number: 1,
name: '《Python从入门到放弃》'
}, {
isChecked: false,
id: 4,
date: '2011-10',
price: 70.02,
number: 1,
name: '《什么都是从入门到放弃》'
}
],
activeName: ''
},
computed: {
total: function() {
return this.books.reduce((returnVal, nextItem) => returnVal + nextItem.price * nextItem.number, 0);
}
},
filters: {
formatPrice: price => '¥' + price.toFixed(2)
},
methods: {
add: function(book, $event) {
console.log(book);
book.number++;
},
mouse: (book, $event) => book.number--,
remove: function(index) {
console.log(this);
this.books.splice(index, 1)
},
selected: function(index) {
this.activeName = index
}
}
})
</script>
</body>
</html>