React之setState方法key设置变量跟获取
1、设置state变量的值
// 例一
this.setState({
[`fileList${index}`]: index
})
// 例二
function(type){
this.setState({
[type]: `file${type}`
})
}
2、获取state变量的值
this.state[`fileList${index}`]
// 例一
this.setState({
[`fileList${index}`]: index
})
// 例二
function(type){
this.setState({
[type]: `file${type}`
})
}
this.state[`fileList${index}`]