-
Notifications
You must be signed in to change notification settings - Fork 0
/
30.路由嵌套.html
56 lines (53 loc) · 1.49 KB
/
30.路由嵌套.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>路由嵌套</title>
</head>
<body>
<div id="app">
<p>
<router-link to="/user/foo">/user/foo</router-link>
<router-link to="/user/foo/profile">/user/foo/profile</router-link>
<router-link to="/user/foo/posts">/user/foo/posts</router-link>
</p>
<router-view></router-view>
</div>
<script src="vue.2.5.js"></script>
<script src="vue-router.js"></script>
<script>
const User = {
template:`
<div class="user">
<h2>User {{route.params.id}}</h2>
<router-view></router-view>
</div>
`
};
const userHome = {
template:'<div>Home</div>'
};
const userProfile = {
template:'<div>userProfile</div>'
};
const userPosts = {
template:'<div>userPost</div>'
};
const router = new VueRouter({
routes:[
{
path: '/user/:id', component: User,
children: [
{path: '', component: userHome},
{path: 'profile', component: userProfile},
{path: 'posts', component: userPosts}
]
}
]
});
const vm = new Vue(
{router}
).$mount('#app');
</script>
</body>
</html>