实时监听组件中路由的变化

实时监听组件中路由的变化,通过watch来进行监听,当路由发生变化时,重新赋值,重新执行从后台获取数据的操作

watch: {
'$route' (to, from) {
this.listQuery.keywords=this.$route.query.keywords
this.searchByKeywords()
}
},
methods: {
searchByKeywords() {
this.$store.dispatch('updateLoading', true)
fetchSearchByKeywords(this.listQuery)
.then(response => {
this.$store.dispatch('updateLoading', false)
this.listTotal = response.data.total
this.listData = response.data.data
})
.catch(error => {
console.log(error)
})
}
}

愿你出走半生,归来仍是少年!
原文地址:https://www.cnblogs.com/wszxx/p/8011498.html