原始情况:表单修改后退出,表格数据变化
openeditDialog(){
if(JSON.stringify(this.currentrow) != "{}"){
this.form = this.currentrow//11111111111111
this.editvisiable = true
}else{
this.$message('请选择一条数据')
}
},
在1中,form=currentrow仅仅是把currentrow的地址给了form,因此改了form中的值以后,currentrow也会变。
解决方案:
这里只需要把这一行改成this.form = JSON.parse(JSON.stringify(this.currentrow))
即可。
原理:
JSON.stringify() 把对象转换成字符串格式 例如
{‘name’:‘steve’,‘age’:‘21’} 变成 '{‘name’:‘steve’,‘age’:‘21’}'
JSON.parse() 把字符串转换成对象格式 例如
{‘name’:‘steve’,‘age’:‘21’} 变成 '{‘name’:‘steve’,‘age’:‘21’}'