data: {
return () {
dataEmp: {
empCode: 'GS1234'
},
dataEmp2: {
empCode: ''
},
}
}
此时修改dataEmp2,dataEmp里面的empCode也会跟着变化;
this.dataEmp2 = this.dataEmp;
this.dataEmp2.empCode = 'GS9999';
console.log( this.dataEmp.empCode);//返回GS9999
console.log( this.dataEmp2.empCode);//返回GS9999
解决方法:
this.dataEmp2 =JSON.parse(JSON.stringify(dataEmp));// here看
this.dataEmp2.empCode = 'GS9999';
console.log( this.dataEmp.empCode);//返回GS9999
console.log( this.dataEmp2.empCode);//返回GS9999