我想在vue路由器定义文件中使用URL参数和查询,以便动态设置标题名称。
我尝试使用$route.params.paramName
格式:
const routes = [
{
path: '/rooms/:room/:id?',
name: `${$route.params.room}`,
component: RoomsView,
meta:{
title: `${$route.params.room} ${$route.params.id} - WebsiteName`
}
}
]
你知道如何访问这些值吗?
我认为最好让组件自己用类似
的东西来呈现逻辑computed: {
title() {
const { name, id } = this.$route.params;
return `${name} ${id} - WebsiteName`;
}
}
我想文档也会给你一些有用的见解