Vuex getter not updating

青春壹個敷衍的年華 提交于 2019-12-03 23:27:32

In your case state.laptops.earmarks is an array, and you are manipulating it by its array index state.laptops[index]. Vue is unable to react to mutations on state arrays (by index). The documentation provides 2 workarounds for this:

// 1. use purpose built vue method:
Vue.set(state.laptops, index, laptop)

// 2. splice the value in at an index:
state.laptops.splice(index, 1, laptop)

Although it is documented, I'm thinking a giant neon glowing sign on that page that says "You will waste hours of productivity if you don't know this" would be a nice addition.

You can read more about this "caveat" here: https://vuejs.org/v2/guide/list.html#Caveats

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