Several methods of object deconstruction

1. Object.assign or... ?

Object.assign(this.formData,res.data[0])

This will assign all the properties of the object to the past, you first look at res.data

2. Array structure

[...oldObj, ...newObj] can remain immutable

3. Spread operator

Spread operator this.formData = res.data[0] ? {...res.data[0]} : this.formData 

4、for 

Just find a way to filter this object by yourself. For in loop or encapsulate a function to handle this situation

for in key 变量[key] = res[key]

5、

const data = res.data[0];

this.formData = {
   ...this.formData,
   ...data
}

6. It is not easy to make mistakes

let props = [all assigned properties] // When the property names correspond to the same
for (let prop of props) { }

7、

 

 In the end I used a for loop

Guess you like

Origin blog.csdn.net/qq_37299479/article/details/127633385