鍍金池/ 問答/HTML5  HTML/ react 的富文本react-draft-wysiwyg 怎么清空內(nèi)容

react 的富文本react-draft-wysiwyg 怎么清空內(nèi)容

1.react-draft-wysiwyg富文本編輯器提交完內(nèi)容后 再次點(diǎn)擊之前的內(nèi)容沒有清空
這個(gè)方法editorState: EditorState.createEmpty()沒有生效

export default class Editors extends React.Component {
    constructor(props) {
    super(props);
    this.state = {
      editorState: EditorState.createEmpty(),
      oper:"",
    };
    this.onChange = (editorState) => this.setState({editorState});
    this.onEditorStateChange=this.onEditorStateChange.bind(this)
  }

  componentWillReceiveProps(newProps) { 
       console.log("屬性改變");
    }  
   componentDidMount (){
      console.log("渲染");
    }

  onEditorStateChange (editorState) {
    this.setState({
      editorState,
    });
    //setFieldsValue是將富文本的內(nèi)容傳給content
    this.props.form.setFieldsValue({content:draftToHtml(convertToRaw(editorState.getCurrentContent()))}); 
  }

 render() {
    const { editorState } = this.state;
    return (
      <div>
        <Editor
          editorState={editorState}
          wrapperClassName="demo-wrapper"
          editorClassName="demo-editor"
          onEditorStateChange={this.onEditorStateChange}
        />
        <textarea
          disabled
          value={draftToHtml(convertToRaw(editorState.getCurrentContent()))}
        />
      </div>
    )
  }
} 

請問大神們怎么解決

回答
編輯回答
脾氣硬

editorState: EditorState.createEmpty()是寫在構(gòu)造函數(shù)里的,也就是說只有組件第一次構(gòu)造的時(shí)候會執(zhí)行

2018年5月24日 15:23