forked from sunseekers/Vue2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routerTransform.html
65 lines (64 loc) · 1.91 KB
/
routerTransform.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>vue-router + transform</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="css/animate.css" rel="stylesheet">
<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'>
<router-link to='/home'>Go to Home</router-link>
<router-link to='/user'>Go to User</router-link>
<button @click='push'>push 路由</button>
<button @click='replace'>替换路由</button>
<div>
<transition enter-active-class='bounceInLeft animated' leave-active-class='bounceOut animated'>
<router-view></router-view></transition>
</div>
</div>
<script type="text/javascript">
const Home={
template:`<span>我是主页</span>`
};
const username={
//$route.params: 表示冒号后面的一个对象
template:`<span>sunseekers</span>`
};
const News={
template:`<div>
<h3>我是用户</h3>
<ul><li><router-link to='/user/sunseekers'>用户信息</router-link></li><ul>
<router-view></router-view>
</div>`
};
const routes=[
{path:'/home',component:Home},
{
path:'/user',component:News,
//配置子路由或者说是嵌套路由,只需要在嵌套或者父路由里面加一个
//children[{path:'',component:}]就好,很形象,很好记
children:[
{path:':username',component:username}
]},
];
const router=new VueRouter({routes});
new Vue({
el:'#router',
router,
methods:{
push(){
router.push({path:'/home'});
},
replace(){
router.replace({path:'/user'})
}
}
})
</script>
</body>
</html>