vue-property-decorator
vue-property-decorator copied to clipboard
oldVal equals to newVal in Watch decorator
Issue #140 is not fixed but is closed!
I change my model to the new val, it triggers the watch listener, but both new and old values equal to the new value (the result of the change).
Is it an expected behavior? Thank you.
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)
@Djaler And how should we check what property the object has changed when mutated?
You can make some hacks. For example, by keeping deep clone of object and comparing new value with this copy (of previous value). But I recommend always return new object rather than mutate the same
Okay, thanks
/close