补充新回答
组件内
routeTo:null //data定义
watch: {
$route: {
handler(to, form) {
this.routeTo = to;
console.log(to);
console.log(form);
},
immediate: true
}
}
获取到name 调用routeTo修改
setTimeout(()=>{
this.routeTo.meta.title='测试测试';
console.log(this.$route)
},1000)
https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241203/e41fb6336281298e237e4ec5e6a31dda.png
旧回答
跳转详情时把要改的名字带上去
this.$router.push({
path: 'xxxxx',
query: {name}//name就是你要显示的名字
});
然后在路由文件里改
{
path: 'xxxxx',
name: 'xx',
component: 'xxxxx',
meta: {
title: '',
},
beforeEnter: (to, from, next) => {
to.meta.title = to.query.name ? `${to.query.name}` : '通用名字';
next()
},
},