vue watch newValue same oldValue bugs All In One
vue watch newValue same oldValue bugs All In One
JSON.stringify
watch: {
obj: function(newValue, oldValue) {
// ❌
console.log(newValue, oldValue);
// ✅
console.log(JSON.stringify(oldValue) === JSON.stringify(newValue));
},
}
old value will be the same as new value ❌
Note: when mutating (rather than replacing) an Object or an Array, the old value will be the same as new value because they reference the same Object/Array.
Vue doesn’t keep a copy of the pre-mutate value.
https://vuejs.org/v2/api/#vm-watch
refs
https://stackoverflow.com/questions/62729380/vue-watch-outputs-same-oldvalue-and-newvalue
https://github.com/vuejs/vue/issues/2164#issuecomment-828139247
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15427072.html
未经授权禁止转载,违者必究!