最近在公司做基于Vue2+element-ui的内部系统,怎么把表单数据传到编辑的页面,ES6有个解决方案
Object.assign()
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
定义:用来将所有可枚举的属性值从一个或多个源对象拷贝到目标对象。结果返回目标对象
语法:
Object.assign(target, ...sources)
target:目标对象
sources:一个或多个源对象
return:目标对象
四个重点:
可被枚举的属性
自身属性
String类型和 Symbol 类型的属性都会被拷贝
Object.assign 会跳过那些值为 null 或 undefined 的源对象
拷贝过程中将调用源对象的getter方法,并在目标对象上使用setter方法实现目标对象的拷贝。
例子:
row:{
startDate: "a",
dueDate: "b"
}
handleEdit: function(index, row) {
this.editFormIndex = index;
this.editForm = Object.assign({}, row);
}
通过handleEdit方法,row(表单行内数据)就拷贝到了this.editForm
在element-ui的