-
Notifications
You must be signed in to change notification settings - Fork 0
/
34.vue2.0路由.html
75 lines (72 loc) · 1.87 KB
/
34.vue2.0路由.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.router-link-active {
background: red;
}
</style>
</head>
<body>
<div id="app">
<route-link to="/home">首页</route-link>
<router-link to="/list">列表页</router-link>
<router-view></router-view>
</div>
<script src="vue2.0.js"></script>
<script src="vue-router.js"></script>
<script>
var Home = {
template: `'<div>
<h1>首页</h1>
<route-link to="/home/login">首页</route-link>
<route-link to="/home/reg">注册</route-link>
<router-view></router-view>
</div>'`
}
var List = {
template: `<div><h1>列表</h1>
<route-link to="/list/news/1">消息1</route-link>
<router-link to="/list/news/2">消息2</router-link>
<router-view></router-view>
</div>`
}
var router = new VueRouter({
routes: [
{
path: "/home", component: Home,
children: [
{
path: 'login', component: {
template: '<div>登录</div>'
}
},
{
path: 'reg', component: {
template: '<div>注册</div>'
}
}
]
},
{path: "/list", component: List,
children:[
{path:'news/:nid',component:{
template:'<div>消息是{{$route.params.nid}}</div>'
},
beforeEnter(to,form,next){
console.log(to.params.nid);
next();
}
}
]},
{path: "*", component: Home},
]
})
var vm = new Vue({
el: "#app",
})
</script>
</body>
</html>