在处理接口返回的数据时,我需要将接口返回的数据(对象)的某些属性用另一个对象进行接收,学习对象解构赋值之前,我一直使用的都是最笨的方法:
this.formData.projectId = res.data.projectId
this.formData.managedcloudId = res.data.managedcloudId
this.formData.regionId = res.data.regionId
this.formData.name = res.data.name
this.formData.ipversion = res.data.ipversion
this.formData.ipAddressEntry = res.data.ipAddressEntry
this.formData.description = res.data.description
this.formData.cloudType = res.data.cloudType
this.formData.id = res.data.id
使用对象解构赋值,只需要两行代码即可解决:
let {projectId ,managedcloudId,regionId, name,ipversion,ipAddressEntry,description,
cloudType,id,regionName,managedcloudName} = res.data
this.formData = {projectId ,managedcloudId,regionId, name,ipversion,
ipAddressEntry,description,cloudType,id,regionName,managedcloudName}