我使用的是一个参数,当我使用this.$router.push()
推送参数时,它可以工作。
routes: {
path: ':stepId?',
name: 'stepper'
}
但是,为了捕捉参数变化(As described in the docs)的值,我也在观察组件中的$route:
watch: {
$route: {
handler: function(to, from) {
const newStepId = (to.params && to.params.stepId) || this.steps[0].id;
const initial = !from;
if (initial || newStepId !== from.params.stepId) {
this.goToStep(newStepId, initial);
}
},
immediate: true
}
}
然而,当我使用back按钮时,watch: $route
内部的路由的to
部分没有任何参数,只有路径,或者手表甚至不运行。
发布于 2020-03-02 20:19:16
我也遇到了同样的问题,对我来说起作用的是在created()方法中添加$watch。
created() {
this.$watch("$route",() => {
// this.$route.query is watched now as expected
},
{ immediate: true });
}
我还是有点不明白,为什么把它装上或像你所做的那样不起作用
https://stackoverflow.com/questions/54700010
复制相似问题