小编典典

反应引用数组

reactjs

我们可以使用类似以下代码的方式将引用数组分配给不同的输入,例如:

<Progressbar completed={25} id="Progress1" ref={(input) => {this.Progress[0] = input }}/>

<Progressbar completed={50} id="Progress2" ref={(input) => {this.Progress[1] = input }}/>

<Progressbar completed={75} id="Progress3" ref={(input) => {this.Progress[2] = input }}/>

但是当我尝试它时,它返回此错误:

Uncaught TypeError: Cannot set property '0' of undefined

而且它不起作用,我是否缺少某些东西?


阅读 270

收藏
2020-07-22

共1个答案

小编典典

在构造函数中创建数组,例如:

constructor(){
  super()

  this.Progress = []
}
2020-07-22