監聽vuex數據的方法
1首先在computed中把數據返回
computed: {
contractFile() {
return this.$store.state.user.contractFile
}
},
2然后在watch中監聽 並操作
immediate:true代表如果在wacth里聲明了之后就會立即執行里面的handler方法
watch: {
contractFile: {
immediate: true,
handler: function (newval) {
this.operations(newval)
}
}},
3 .此時如果VUEX里的數據發生改變,會同時觸發this.operations();
4.注釋:此方法也可用於app.vue監聽this.$route變化
5 監聽router數據
組件內