Closed enloc-port closed 1 year ago
Can anyone at least confirm that this is a thing and maybe say whether it's a bug or a feature?
@yyx990803 @kiaking If you cannot say anything about this, would you mind telling me who to contact in order to get a reaction to this issue?
This is neither a feature or a bug.
You're mutating the state directly. You can verify this claim by enabling strict mode and observing the console error when modifying the model value.
In your example, a shallow object can be spread into a new object as to avoid this conflict, for example:
computedObject() {
return { ...this.$store.state.someList.at(-1) };
}
Feel free to file a new issue if you discover anything else 👍
Version
Vue: 2.6.14 Vuex: 3.5.1
Description
We did not find any documentation of the behavior we encountered with the store's
commit()
method when working with a list of objects, so we do not know what to make of it.It seems like any call to
commit()
persists all pending changes to the state, even if the method called incommit()
does not do anything.In the example below, when editing one of the fields and clicking "Commit nothing", the changes are persisted in the state, even though the store's
doNothing()
method did not do anything.The Vuex "Mutations" page does not address this at all, hence we wonder, is this a bug or intended behavior? In case of the latter, it should be documented and emphasized on the "Mutations" page, because it is very unintuitive.
Example
example.vue
store.js