我无法理解......想要这个vue!如果可以的话请帮忙!这是我的代码
var groupadding = new Vue({
el: '#groupAdd',
data:{
currentFullData: [],
localData: []
},
methods: {
getDepartment() {
var sendData = id; // this is example
this.$http.post('some api ', sendData, {emulateJSON: true})
.then( resp => {
this.currentFullData = resp.data;
}
},
getLocalDepartment() {
this.localData = this.currentFullData;
}
}
})
例如在 currentFullData 中,我有 4 个布尔字段,“创建”、“读取”、“更新”、“删除”
这 4 个字段也获取 localData,但是当我更改 localData 中的一些时,它们也会更改 currentFullData !!!!!!!!!!!!!!!
soooooo 任何人都可以解释我wtf 这是?!?!?!
这是因为您实际上是在修改同一个对象(如您所写this.localData = this.currentFullData;
)
如果要使用 currentFullData 初始化 this.localData,则需要复制它:
this.localData = Object.assign({}, this.currentFullData);
见https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句