项目中应用了vuex
plan
const state= {
planList: [{
id: "1",
layout: {
nodes: [],
currentNodeId: ""
}
}],
currentPlanId: "1"
}
const getters = {
currentPlan: state => state.planList.find(
item => item.id === state.currentPlanId
),
currentLayout: (state, getters) => getters.currentPlan.layout
}
const mutations = {
setPlanList(state, planList) {
if (Array.isArray(planList)) {
state.planList = planList.map(item => {
return createPlan(item);
});
}
},
setLayout(state, layout) {
// 这里有什么好的方法修改layout呢?
state.planList.find(
item => item.id === state.currentPlanId
).layout = layout;
},
setCurrentNode(state, nodes) {
// nodes是一个层层嵌套的结构
}
}
setLayout(state, layout) 这里有什么好的方法修改layout呢?