Vue.js 当另一个观察程序正在运行时,取消对任何观察程序的跟踪

Vue.js 当另一个观察程序正在运行时,取消对任何观察程序的跟踪,vue.js,vuejs2,vue-component,vue-router,Vue.js,Vuejs2,Vue Component,Vue Router,我将路由路径设置为路径:'/:homeCode?',homeCode是可选的,因此我将?保留在末尾。 问题:当我通过homeCode时,调用“$route.params.homeCode”,但立即执行下一个路由,即选项。当运行'$route.params.homeCode'时,如何停止执行选项监视程序 编辑1: 我有外部分页选项: watch: { options: { handler () { this.get_re_list() .the

我将路由路径设置为
路径:'/:homeCode?',
homeCode
是可选的,因此我将
保留在末尾。 问题:当我通过
homeCode
时,调用
“$route.params.homeCode”
,但立即执行下一个路由,即
选项。当运行
'$route.params.homeCode'
时,如何停止执行
选项
监视程序

编辑1:

我有外部分页选项:

watch: {
options: {
      handler () {
        this.get_re_list() 
            .then(data => {
                this.re = data.result
                this.totalM = data.count
            })
      },
      deep: true,
    },
'$route.params.homeCode':  {
  handler () {
    return new Promise((resolve, reject) => {
          reApi.getRe({page:'', count:'', home:this.$route.params.homeCode}) 
            .then(re => {
                this.re = re.result
                this.totalRe = re.count
            })
            .catch(error => {
                return reject(error)
            })
      })
  },
  deep: true,
  immediate: true
}
},

您是否需要监视程序中的
选项
,它不能在
挂载
或创建的
上运行?
此外,
watch
功能确实会返回一个
unwatch
,不过您需要再次设置watcher。请参见此处:
.
一个可能更简单的解决方案是,只需在内存中将变量设置为
true
<代码>路线
观察并在选项观察中进行检查。
像这样:


您是否需要监视程序中的
选项
,它不能在
挂载
或创建的
上运行?
options: {
          page: 1,
          itemsPerPage: 40,
        },
watch: {
options: {
      handler () {
        if (this.routeCalled) return
        this.get_re_list() 
            .then(data => {
                this.re = data.result
                this.totalM = data.count
            })
      },
      deep: true,
    },
'$route.params.homeCode':  {
  handler () {
    this.routeCalled = true
    return new Promise((resolve, reject) => {
          reApi.getRe({page:'', count:'', home:this.$route.params.homeCode}) 
            .then(re => {
                this.re = re.result
                this.totalRe = re.count
            })
            .catch(error => {
                return reject(error)
            })
      })
  },
  deep: true,
  immediate: true
}
},