React之setState方法key设置变量跟获取

1、设置state变量的值

// 例一
this.setState({
  [`fileList${index}`]: index
})
// 例二
function(type){
  this.setState({
    [type]: `file${type}`
  })
}

2、获取state变量的值

this.state[`fileList${index}`]
posted @ 2021-04-27 09:54  春燕啄春泥  阅读(491)  评论(0编辑  收藏  举报