End.
原
vue中监听路由参数变化
vue页面url参数变化了,改变一些变量数据。
可以使用如下方式,在watch,监听 $route。
watch: {
$route() {
this.showTab = this.$route.query.tab || 'base'
}
},
也可以用如下方式:
watch: {
$route: {
handler(newVal, oldVal) {
if (newVal) {
this.showTab = this.$route.query.tab || 'base'
}
}
}
},
也可以监听指定的参数,如下:
watch: {
'$route.query.tab': {
handler(newVal, oldVal) {
if (newVal) {
this.showTab = newVal || 'base'
}
}
}
},
监听tab参数变化,进行数据处理。
End.