forked from sunseekers/Vue2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththis.$router.html
57 lines (57 loc) · 1.61 KB
/
this.$router.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>this.$router 和 $route 的区别</title>
<meta name="description" content="">
<meta name="keywords" content="">
<script type="text/javascript" src='js/vue.min.js'></script>
<script type="text/javascript" src='js/vue-router.js'></script>
</head>
<body>
<div id='router'>
<h1>Hello App !</h1>
<ul>
<router-link tag='li' to='/home' >Go to Home</router-link><br/>
<router-link tag='li' to='/new'> $route是当前的路由信息 {{$route}}</router-link>
</ul>
<router-view></router-view>
</div>
<script type="text/javascript">
//1.创建组件
const Home={
template:`<span>我是主页</span>`
};
const News={
template:`<span>我是新闻</span>`
};
//2.配置路由
const routersname=[
{
path:'/home',name:'我是主页',component:Home
},
{
path:'/new',name:'我是新闻',component:News
},
//重定向.相当于404,
{
path:'*',redirect:'/home'
}
];
//3.生成路由实例
const router=new VueRouter({
routes:routersname
//此时 routers 和 routername 并不相等,所以不能在采用 es6 里面对象的简写方法
});
new Vue({
el:'#router',
router,
mounted(){
console.log('this.$router是路由的实例:');
console.log(this.$router);
}
})
</script>
</body>
</html>