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
}
},