在watch中监听Vuex中state的数据

watch监听

方法一:

在computed 计算属性和watch 监听中 写入
export default{
	component:{},
	data(){
		return{}
	},
	computed:{
		tagArr(){
			return this.$store.state.homex.tag
		}
	},
	watch:{
		tagArr(newVal,oldVal){
			//对数据进行操作
			console.log(newVal,oldVal)
		}
	},
	methods:{},
}

方法二:

在watch 中写入
export default{
	component:{},
	data(){
		return{}
	},
	computed:{},
	watch:{
		'$store.state.homex.tag'(newVal,oldVal){
			//对数据进行操作
			console.log(newVal,oldVal)
		}
	},
	methods:{},
}
Logo

前往低代码交流专区

更多推荐