Vue-router参数未使用后退按钮更新

问题描述 投票:3回答:1

我正在使用参数,当我使用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
  }
}

但是,当我使用后退按钮时,to内路径的watch: $route部分没有任何参数,只有路径,或者手表甚至没有运行。

vue.js vue-router back-button
1个回答
1
投票
created() { this.$watch("$route",() => { // this.$route.query is watched now as expected }, { immediate: true }); }

对我还是不清楚,为什么将它安装在上面或者像你所做的那样不起作用

© www.soinside.com 2019 - 2024. All rights reserved.