-
Notifications
You must be signed in to change notification settings - Fork 4
/
sample.html
104 lines (89 loc) · 2.57 KB
/
sample.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
<!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>Vue Router</title>
<script src="../../lib/vue.js"></script>
<script src="../../lib/vue-router.js"></script>
<style>
.container {
background-color: aquamarine;
margin-top: 20px;
width: 740px;
height: 300px;
}
</style>
</head>
<body>
<div id="app">
<!-- 通过 router-link 标签来生成导航链接 -->
<router-link to="/home">主页</router-link>
<router-link to="/account">账户</router-link>
<div class="container">
<!-- 将选中的路由渲染到 router-view 下-->
<router-view></router-view>
</div>
</div>
<template id="tmpl">
<div>
<h3> account page </h3>
<!-- 生成嵌套子路由地址 -->
<router-link to="/account/login">登录</router-link>
<router-link to="/account/register">注册</router-link>
<!-- 生成嵌套子路由渲染节点 -->
<router-view></router-view>
</div>
</template>
<script>
// 1、定义路由跳转的组件模板
const home = {
template: '<div> home page </div>'
}
const account = {
template: '#tmpl'
}
const login = {
template: '<div> login page</div>'
}
const register = {
template: '<div> register page</div>'
}
// 2、定义路由信息
const routes = [{
path: '/',
redirect: '/home'
},
{
path: '/home',
component: home
},
{
path: '/account',
component: account,
children: [{
path: 'login',
component: login
},
{
path: 'register',
component: register
}
]
}
]
const router = new VueRouter({
//mode: 'history', //使用 history 模式还是 hash 路由模式
routes
})
// 3、挂载到当前 Vue 实例上
const vm = new Vue({
el: '#app',
data: {},
methods: {},
router: router
});
</script>
</body>
</html>