實時監聽組件中路由的變化,通過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)
})
}
}