vue-vuerouter-basic

VueRouter Basic

一个vuerouter的例子,这里引入了vue,vue-router,app.js需要自己编写

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>basic</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="../vue.min.js"></script>
<script src="../vue-router.min.js"></script>
</head>
<body>
<div id="app"></div>
</body>
<script src="app.js"></script>
</html>

app.js 文件内容

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
// 1.定义几个component
const Home = {
template: `<div>home</div>`
}
const Foo = {
template: '<div>foo</div>'
}
const Bar = {
template: `<div>bar</div>`
}
const Unicoede = {
template: `<div>unicode</div>`

}
// 2.创建一个 router 实例
const router = new VueRouter({
routes: [
{ path: "/", component: Home },
{ path: "/foo", component: Foo },
{ path: "/bar", component: Bar },
{ path: '/é', component: Unicoede }
]
});


// 3.创建一个Vue实例
new Vue({
// 引入前一步创建的vue实例
router,
template: `
<div id="app-content">
<h1>Basic</h1>
<ul>
<li>
<router-link to="/">/</router-link>
</li>
<li>
<router-link to="/foo">/foo</router-link>
</li>

<li>
<router-link to="/bar">/bar</router-link>
</li>
<!-- router-link 可以渲染成其他的组件,这里就渲染成了li,虽然中间包裹的 <a> 标签指向 /bar,
但实际运行时 依然是连接到foo-->

<router-link tag="li" to="/foo" :event="['mousedown','touchstart']">
<a>/bar</a>
</router-link>
</ul>
<router-view class="view"></router-view>
</div>
`
}).$mount('#app');
作者

Bruce Liu

发布于

2018-11-29

更新于

2022-11-12

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.