如何将数据从 Vuex 状态克隆到本地数据? [英] How can I clone data from Vuex state to local data?

查看:20
本文介绍了如何将数据从 Vuex 状态克隆到本地数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数据从 vuex 状态克隆到本地数据属性?

How can I clone data from vuex state to local data attribute?

状态

this.tsStore.shemes

this.tsStore.shemes

数据属性

data () {
  return { shemes: [] }
}

我已经尝试在更新的 () this.shemes = this.tsStore.shemes 中执行此操作,但它似乎还剩下一个绑定.. 因为当我删除 this.shemes 中的一项时单击时,我还删除了状态中的该项目,并收到不要在变异处理程序之外改变 vuex 存储状态"的错误.

I've tried do this in updated () this.shemes = this.tsStore.shemes but it's seems like it has a binding left.. because when i delete one item in this.shemes on click i've also delete that item in the state and get the error of "Do not mutate vuex store state outside mutation handlers".

我需要克隆状态并对该数据做任何我需要做的事情,同时不要影响我的状态.

I need to clone the state and do what ever I need to do with that data and on the same time don't affect my state state.

推荐答案

try

this.shemes = JSON.parse ( JSON.stringify ( this.tsStore.shemes) )

这将从存储中的数组中克隆所有值和对象.

This will clone all value and objects from the array in the store.

这篇关于如何将数据从 Vuex 状态克隆到本地数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆