【发布时间】:2020-10-31 23:51:30
【问题描述】:
在我的组件中,我声明了一些这样的数据:
data() {
return {
defaultValue: {json object with some structure},
activeValue: {}
...
并且在组件方法中复制这个值:
this.activeValue = this.defaultValue
但问题是,更改 this.activeValue 值后,this.defaultValue 也发生了变化。
如果我使用 Object.freeze(this.defaultValue) 并尝试更改 this.activeValue 我得到错误 - 对象不可写。
如何在没有参考的情况下复制数据?
【问题讨论】:
标签: javascript json vue.js reference copy