vue-router命名路由
例子如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="lib/vue_2.5.22.js"></script>
<script src="lib/vue-router_3.0.2.js"></script>
</head>
<body>
<div id="app">
<router-link to="/user/1">User</router-link>
<router-link to="/user/2">User</router-link>
<router-link :to="{name:'user',params:{id:3}}">User</router-link>
<router-link to="/register">Register</router-link>
<router-view></router-view>
</div>
<script>
var User = {
props: ['id', 'uname', 'age'],
template: `<div>
User组件--用户的id是:{{uname}},{{age}},{{id}}
</div>`
}
var Register = {
template: `<div>Rgister组件</div>`
}
var router = new VueRouter({
routes: [
{ path: '/', redirect: '/user' },
{
name: 'user',
path: '/user/:id', component: User, props: route => ({
uname: 'zs', age: 12, id: route.params.id
})
},
{ path: '/register', component: Register },
]
})
new Vue({
el: '#app',
router
})
</script>
</body>
</html>