vue 组件route参数跳转,更新页面数据
需求:
页签页面,存于keep-alive中,切换或者跳转回来时,需要刷新页面。两种方式
方案一:
使用watch,但watch会缓存,开多少个页签,再跳转回来,就会重复执行,除非在deactivated时,进行销毁
销毁watch this.unwatch = this.$watch('xx',function(){})
deactivated() {
this.unwatch()
}
watch: { // 解决tab存在时,跳转进来不刷新问题 $route(newValue, oldValue){ console.log(newValue) console.log(oldValue) if(this.$route.params.taskId>0) { this.queryParam.taskId = this.$route.params.taskId this.pagination.current = 1 } console.log(this.pagination) this.getList() }, // 项目切换时,刷新页面 currentProject(newValue) { if(newValue) { this.getList() } } },
方案二(推荐):
来回切换只会触发deactivated和activated声明周期,在activated处理就好
activated () { if(this.$route.params.taskId>0) { this.queryParam.taskId = this.$route.params.taskId this.pagination.current = 1 } console.log(this.pagination) this.getList() },
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架