(这不是重复的问题,请通读)
这两行有什么区别:
[name]: value
这:
name: value
我像here一样四处搜寻,但不了解这行的内容:
handleInput(e) {
let value = e.target.value;
this.setState(
prevState => ({
newUser: {
...prevState.newUser,
name: value
}
}),
() => console.log(this.state.newUser)
);
}
handleInput(e) {
let value = e.target.value;
let name = e.target.name;
this.setState(
prevState => ({
newUser: {
...prevState.newUser,
[name]: value
}
}),
() => console.log(this.state.newUser)
);
}
在以上两个代码中,有什么区别?
这里是状态:
this.state = {
newUser: {
name: "",
age: "",
gender: "",
skills: [],
about: ""
},