解决多个路由绑定同一个组件 获取参数只获取一次的方法
2023-09-27 14:26:44 时间
{
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()
}
}
相关文章
- 学习ASP.NET Core Blazor编程系列十——路由(上)
- C#调用接口注意要点 socket,模拟服务器、客户端通信 在ASP.NET Core中构建路由的5种方法
- HCIE-Security Day23:DSPN+NHRP+Mgre:实验(二)配置非shortcut方式DSPN(OSPF路由协议)
- egg 项目实战(二)初始Egg.js中的路由
- Flutter移动电商实战 --(40)路由_Fluro的全局注入和使用方法
- vue 中 this.$router.push() 路由跳转传参 及 参数接收的方法
- 华为数通笔记-ospf路由计算
- 4.2 路由算法与路由协议概述
- vue重复点击路由 导致冗余导航的解决方法
- ASP.NET Web API 路由
- 【Vue】 vue2路由搭建和搭建vue2脚手架(入门级)
- react路由、NavLink组件封装
- 8、三分钟让你真正了解常见的OSPF动态路由协议
- 5、路由器解析与静态路由
- Vue路由导航报错:NavigationDuplicated: Avoided redundant navigation to current location解决方法
- Vue路由传递query参数的两种方式
- 破解电信光猫华为HG8120C关闭路由功能方法