react 的富文本react-draft-wysiwyg 怎么清空内容

1.react-draft-wysiwyg富文本编辑器提交完内容后 再次点击之前的内容没有清空
这个方法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是将富文本的内容传给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>
    )
  }
} 

请问大神们怎么解决

阅读 4.3k
1 个回答

editorState: EditorState.createEmpty()是写在构造函数里的,也就是说只有组件第一次构造的时候会执行

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题