textarea 适应文本高度的文本域

解决方法:

  • 通过scrollHeight用脚本改变文本域高度
  1. // rows 是默认的textarea的高度
  2. <textarea rows="1" maxLength="40" placeholder="" style={{ height: '0.58rem' }} ref="textareas" onInput={this.textareaChange} />
  textareaChange = () => {
    this.refs.textareas.style.height = 'auto'
    this.refs.textareas.style.height = `${this.refs.textareas.scrollHeight}px`
  }