{
path: '/application',
title: '我的工作',
icon:'code-working',
name: 'application',
component: Main,
children: [
{
path: 'index/:id', title: '我的申請', name: 'myApplication', component: resolve => {
require(['@/views/application/index'], resolve);
}
},
{
path: 'index/:id', title: '我的待辦', name: 'have not done', component: resolve => {
require(['@/views/application/index'], resolve);
}
},
{
path: 'index/:id', title: '我的已辦', name: 'have been done', component: resolve => {
require(['@/views/application/index'], resolve);
}
}
]
},
這三個路由繫結的是同一個元件,在
created(){
console.log(this.$route.params.id)
}
裡面這種動作只會執行一次,也就是隻能拿到該元件建立時的路由id,
如果要獲得不同的id必須使用官方推薦的方法
響應路由引數的變化
const User = {
template: '...',
watch: {
'$route' (to, from) {
// 對路由變化作出響應...
}
}
}
或者使用 2.2 中引入的 beforeRouteUpdate 守衛:
const User = {
template: '...',
beforeRouteUpdate (to, from, next) {
// react to route changes...
// don't forget to call next()
}
}