How to modify deep vuex data with v-model

眉间皱痕 提交于 2019-12-25 03:24:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!