05_04.router-link标签
2017-11-18 本文已影响0人
Robyn_Luo
1. 代码演示
<!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>Document</title>
</head>
<body>
<div id="app">
{{ msg }}
<!-- 路由占位 -->
<router-view></router-view>
<nav>
<a href="#/login?name=zhangsan&age=17">登陆</a>
<a href="#/register">注册</a>
<a href="#/detail/abc/acb/abc/10/20">详情</a>
</nav>
<nav>
<router-link v-bind:to="login">登陆</router-link>
<router-link to="/register">注册</router-link>
<router-link v-bind:to="{ name: 'xl', params: { id: 10, uid: 20 } }">详情</router-link>
</nav>
</div>
<script src="vue.js"></script>
<script src="vue-router.js"></script>
<script>
// 登陆组件配置项
var LoginComponent = {
template: `<div>{{ msg }}</div>`,
data() {
return {
msg: "我是登陆页面",
};
}
};
// 注册组件配置项
var RegisterComponent = {
template: `<div>{{ msg }}</div>`,
data() {
return { msg: "我是注册页面" }
}
};
// 详情组件配置项
var DetailComponent = {
template: `<div>{{ msg }}</div>`,
data() {
return { msg: "我是详情页面" }
}
};
var vm = new Vue({
el: '#app',
data: {
msg: '路由演示',
login: {
path: '/login',
query: {
name: 'zhangsan',
age: 16
}
}
},
// 路由配置
router: new VueRouter({
// 路线配置
routes: [
{ path: '/login', component: LoginComponent },
{ path: '/register', component: RegisterComponent },
{ name: 'dl', path: '/detail/abc/abc/abc/:id/:uid', component: DetailComponent }
]
}),
// 组件初始化完毕, 数据也绑定完毕后执行
created() {
console.log(this);
}
});
</script>
</body>
</html>