-
Notifications
You must be signed in to change notification settings - Fork 4
/
decoupling.html
137 lines (125 loc) · 4.22 KB
/
decoupling.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
<!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">
<title>Decouple component from Router</title>
<script src="../../lib/vue.js"></script>
<script src="../../lib/vue-router.js"></script>
<link rel="stylesheet" href="../../css/bootstrap.min.css">
<style>
.main {
background-color: antiquewhite;
height: 500px;
padding: 10px 10px;
}
</style>
</head>
<body class="container-fluid">
<div id="app">
<div class="main">
<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
<div class="btn-group mr-2" role="group" aria-label="First group">
<button type="button" class="btn btn-secondary" @click="goFirst">第一页</button>
<button type="button" class="btn btn-secondary" @click="goSecond">第二页</button>
<button type="button" class="btn btn-secondary" @click="goThird">第三页</button>
<button type="button" class="btn btn-secondary" @click="goFourth">第四页</button>
</div>
<div class="btn-group mr-2" role="group" aria-label="Second group">
<button type="button" class="btn btn-secondary" @click="pre">后退</button>
<button type="button" class="btn btn-secondary" @click="next">前进</button>
</div>
<div class="btn-group mr-2" role="group" aria-label="Third group">
<button type="button" class="btn btn-secondary" @click="replace">替换当前页为特殊页</button>
</div>
</div>
<router-view></router-view>
</div>
</div>
<script>
const first = {
template: '<h3>当前是第一页</h3>'
}
const second = {
props: ['id'],
template: '<h3>当前是第二页 --- {{id}} </h3>'
}
const third = {
props: ['name'],
template: '<h3>当前是第三页 --- {{name}} </h3>'
}
const fourth = {
props: ['id', 'name'],
template: '<h3>当前是第四页 --- {{id}} --- {{name}} </h3>'
}
const special = {
template: '<h3>特殊页面</h3>'
}
const router = new VueRouter({
routes: [{
path: '/first',
component: first
}, {
path: '/second/:id',
component: second,
props: true
}, {
path: '/third/:name',
component: third,
props: {
name: 'zhangsan'
}
}, {
path: '/fourth',
component: fourth,
props: (route) => ({
id: route.query.id,
name: 'zhangsan'
})
}, {
path: '/special',
component: special
}]
})
const vm = new Vue({
el: '#app',
data: {},
methods: {
goFirst() {
this.$router.push({
path: '/first'
})
},
goSecond() {
this.$router.push({
path: '/second'
})
},
goThird() {
this.$router.push({
path: '/third'
})
},
goFourth() {
this.$router.push({
path: '/fourth'
})
},
next() {
this.$router.go(1)
},
pre() {
this.$router.go(-1)
},
replace() {
this.$router.replace({
path: '/special'
})
}
},
router: router
})
</script>
</body>
</html>