vue深拷贝浅拷贝

2,729 阅读1分钟

openUpdateForm (user) {
        this.userUpdate = user
        this.showUpdateDialog = true
      },

在vuejs的项目里,通过上面的函数,将user的值复制给userUpdate

(user和userUpdate是Object)

但是当我修改userUpdate的值的同时,user的值也跟着改变。

如果只想改变userUpdate的值,

openUpdateForm (user) {
        this.userUpdate = JSON.parse(JSON.stringify(user))
        this.showUpdateDialog = true
      },

这样就不会连带着user一起改变了。~~