vue 路由带参跳转
1、路由配置文件中(router.js或router/index.js等)中应设置:
// 跳转至router 携带id和name
{
path: 'router/:id/:name',
name: 'router',
component: () => import('@/views/router/router'),
meta: { title: '页面名称'},
}
2、跳转执行处应设置:
this.$router.push({
name: 'router',
params:{id: id,name: name}
})
3、跳转的目标页面获取参数:
watch:{
"$route"(val,oldval){
this.id = val.params.id
this.name = val.params.name
this.tempRoute = Object.assign({}, this.$route)
},
created() {
this.id =this.$route.params.id
this.name =this.$route.params.name
},