forked from shy1118999/vue.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
030-路由-路由的嵌套.html
58 lines (56 loc) · 1.71 KB
/
030-路由-路由的嵌套.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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title></title>
<!-- 引入vue.js -->
<script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script>
<!-- 引入路由模块 -->
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
<div id='app'>
<router-link to="/account">Account</router-link>
<router-view></router-view>
</div>
<template id="tmp1">
<div>
<h1>这是account组件</h1>
<router-link to="/account/login">登录</router-link> |
<router-link to="/account/register">注册</router-link>
<router-view></router-view>
</div>
</template>
</body>
<script>
let account = {
template:"#tmp1"
}
let login = {
template:"<h1>登录组件</h1>"
}
let register = {
template:"<h1>注册组件</h1>"
}
let router = new VueRouter({
routes:[
{path:'/account',component:account,children:[ //children子路由
{path:'login',component:login},//path开头不要加“/”
{path:'register',component:register}
]},
// {path:'/account/login',component:login},
// {path:'/account/register',component:register}
]
})
// 实例化vue对象
let vm = new Vue({
// 绑定对象
el:'#app',
data:{
},
methods:{
},
router
})
</script>
</html>