我正在使用VueJS构建应用程序,我正在使用Apollo客户端通过GrapgQL服务器从数据库中获取数据.我的代码看起来像这样:
apollo.query({
query,
variables
})
// context.commit('populateComments', payload) triggers the mutation
.then(payload => context.commit('populateComments', payload))
Run Code Online (Sandbox Code Playgroud)
然后,在我的突变中,我有以下内容
populateComments: (state, payload) => {
state.comments = payload.data.comments
}
Run Code Online (Sandbox Code Playgroud)
当我尝试将另一个对象推入另一个突变的comments数组时,我得到一个错误,上面写着"无法添加属性300,对象不可扩展".我发现以下工作
state.comments = Array.from(payload.data.comments)
Run Code Online (Sandbox Code Playgroud)
但是......我不确定反复复制像这样的大型数组有多有效?这是首选的方法吗?