是否可以防止 Vue 组件内的路由更改(不在我的路由器文件内)?
我的情况使用相同的组件,但 URL 发生变化 (/users/1
-> /users/2
)
Vue.extend({
data: () => ({
active: true
}),
beforeRouteLeave(to, from, next){
if (this.active) {
// do not redirect
} else {
next();
}
}
})
我的理解是,这在导航 URL 时不起作用,但 View /组件保持不变。
最佳答案
我需要使用 beforeRouteUpdate
而不是 docs 中所述的 beforeRouteLeave
beforeRouteUpdate(to, from, next) {
if (this.active) {
next(false);
} else {
next();
}
},
关于vue.js - 防止 Vue 组件内的路由更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67859621/