【发布时间】:2019-07-09 01:07:39
【问题描述】:
我正在使用参数,当我使用 this.$router.push() 推送参数时,它可以工作。
routes: {
path: ':stepId?',
name: 'stepper'
}
但是,我也在观察组件内部的 $route 以捕捉参数值的变化 (As described in the docs):
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
}
}
但是,当我使用后退按钮时,watch: $route 内的路线的to 部分没有任何参数,只有路径或者手表甚至没有运行.
【问题讨论】:
标签: vue.js vue-router back-button