问题
I'm trying to modify a vuex store, but using v-model on a key deep inside the object. Obviously when modifying data it must be done using mutations. But i'm struggling to figure out how to do this with a deep value.
Here's a fiddle, which should generate a vuex error (the error isn't generated in the fiddle for some reason):
[vuex] Do not mutate vuex store state outside mutation handlers
https://jsfiddle.net/antony_publica/L27pcksn/70/
How can I setup a computed value for an object thats inside an object returned from a state without having to copy that entire dataset to another variable and track all the changes manually?
回答1:
You won't be able to use a computed property for this. Don't use v-model
, instead bind to :value
and register your own event listener.
https://jsfiddle.net/jamesbrndwgn/L27pcksn/88/
You may also want to read about normalizing state shape. It will make working with Objects much simpler and avoid deep nesting.
来源:https://stackoverflow.com/questions/53843292/how-to-modify-deep-vuex-data-with-v-model