菜单栏增加单页面刷新功能

1.移除带参路由来回切换data
2.只刷新当前router,不影响其他已缓存的router
This commit is contained in:
王珏
2020-08-25 10:15:25 +08:00
parent 6a6f920a97
commit c9da05eb8f
4 changed files with 14 additions and 32 deletions

View File

@@ -39,38 +39,8 @@ export default {
},
data () {
return {
datas: [],
data: { value: '' }
}
},
methods: {
switchData (id) {
let data = this.datas[id]
if (!data) {
data = { value: '' }
this.datas[id] = data
}
this.data = data
}
},
// 第一次进入或从其他组件对应路由进入时触发
beforeRouteEnter (to, from, next) {
const id = to.params.id
if (id) {
next(instance => instance.switchData(id))
} else {
next(new Error('未指定ID'))
}
},
// 在同一组件对应的多个路由间切换时触发
beforeRouteUpdate (to, from, next) {
const id = to.params.id
if (id) {
this.switchData(id)
next()
} else {
next(new Error('未指定ID'))
}
}
}
</script>

View File

@@ -1,6 +1,7 @@
export default {
beforeRouteEnter (to, from, next) {
next(instance => instance.$router.replace(from.fullPath))
from.meta[from.path] = Date.now()
next(instance => instance.$router.replace({ path: from.fullPath, meta: from.meta }))
},
render: h => h()
}