我有这样的Vuex吸气剂:
sectionsAndSubSectionsJoined(state) {
var sections = state.aBMudbone.sections;
var subsections = state.aBMudbone.subSections;
var combinedSections = [];
_.forEach(sections, function (section) {
var subSectionsFiltered = _.filter(subsections, ['sectionId', section.sectionId]);
var sectionAndSubSections = section;
sectionAndSubSections.children = subSectionsFiltered;
combinedSections.push(sectionAndSubSections);
});
return combinedSections
}
在控制台中,出现以下错误:
[vuex] do not mutate vuex store state outside mutation handlers.
显示此错误的行是:
sectionAndSubSections.children = subSectionsFiltered;
据我了解,即使sections
,subSections
和sectionAndSubSections
是新对象,因为它们是从存储状态创建的,因此它们会受到某种约束,因此在我发出警告时尝试添加到此状态。
如何将这个新状态从商店状态中断开,这样我就不会收到此警告?