MyTextArea .js
import 'braft-editor/dist/index.css'
import React from 'react'
import BraftEditor from 'braft-editor'
/**
* 基于braft-editor的富文本编辑器
* 调用时提供对象
* {
* onchange (function) 改变方法
* hisContentText (string) 默认值
* }
*/
export default class MyTextArea extends React.Component {
//初始化editorState对象
state = {
editorState: BraftEditor.createEditorState('<p><b>开始您的创作</b></p>'), // 设置编辑器初始内容
outputHTML: '<p></p>'
}
//应对回填场景,修改编辑器内容
componentDidMount () {
this.isLivinig = true
// 0.2秒后更改编辑器内容
setTimeout(this.setEditorContentAsync, 200)
}
componentWillUnmount () {
this.isLivinig = false
}
/**
* 编辑器值改变,调用父类方法传递值
* @param editorState
*/
handleChange = (editorState) => {
this.setState({
editorState: editorState,
ou