Vue 使用beforeRouteEnter获取上一个页面Url的参数,获取为null?

新手上路,请多包涵
data() {
    return {
        oldUrl: null,
    }
}

1、这里console.log是有值的,

  beforeRouteEnter (to, from, next){
    next(vm => {
      // 通过 `vm` 访问组件实例,将值传入oldUrl
      vm.oldUrl = from;
    })
  },

2、在mounted console.log 为null
image.png
image.png

阅读 1.6k
1 个回答

beforeRouteEnter的next里的回调函数晚于mounted执行,就是vm.oldUrl是晚于mounted的,可以把mounted或其他逻辑封装函数,在next中执行

推荐问题