我想知道我是否做得正确。使用 Vue3 和 Vuex4。
list
我在我的商店中有一个名为的数组,如下所示:
const store = createStore({
plugins: [createPersistedState()],
state() {
return {
list: [{
name: makeid(7),
id: makeid(5),
group: {
head: false,
inGroup: 0,
pos: 0.0
}
}]
}
要添加/删除元素,我使用突变并随后对数组进行排序。在我的组件中,我得到这样的数组:
let list = reactive(store.getters.getList);
动作被称为:
store.dispatch('pushElement', el)
store.dispatch('removeElement', id)
使用reactive
. 但我想知道是否更喜欢使用computed property
列表而不是反应数组?我已经试过了
list = computed () => {get()..., set()...}
但是从数组中删除元素时遇到问题。
那么,我在这里做吗?
编辑:
正如建议的那样,我现在将计算属性用于只读方面,例如:
let list = computed({
get: () => {
return store.getters.getList;
}
});