为什么watch监听变量变化的时候,都会触发两次里面的函数,只能才能执行一次?
比如说下面这个代码,我希望用watch监听lineArray的变化,但是每次发生变化的时候,总会执行两次dispatch,怎么才能只执行一次dispatch
watch: {
"formData.roadbookArea": {
handler: function(newVal, oldVal) {
console.log("newVal == ", newVal);
console.log("oldVal == ", oldVal);
},
changeDataRoadSend(newVal, oldVal) {
console.log("changeDataRoadSend newVal == ", newVal);
console.log("changeDataRoadSend oldVal == ", oldVal);
}
},
dataRoadSend(newVal, oldVal) {
// console.log('dataRoadSend newVal ==', newVal)
// console.log('dataRoadSend oldVal ==', oldVal)
},
lineArray(newVal, oldVal) {
// console.log('lineArray newVal ==', newVal);
// console.log('lineArray oldVal ==', oldVal);
// console.log(this);
if (newVal.length !== 0) {
// this.$store.dispatch('addNewRoadDate', newVal)
}
}
},