Commit aa2b1558 authored by zhuyangbin's avatar zhuyangbin

update

parents 75c77dde 8651474a
...@@ -38,13 +38,14 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef, ...@@ -38,13 +38,14 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef,
const [editorState, setEditorState] = useState(BraftEditor.createEditorState(null)); const [editorState, setEditorState] = useState(BraftEditor.createEditorState(null));
const [percent, setPercent] = useState(0); // 进度条 const [percent, setPercent] = useState(0); // 进度条
const previewRef = useRef(null); const previewRef = useRef(null);
useEffect(() => { useEffect(() => {
if (value && typeof value === 'object') { // 不做转换
setEditorState(value)
} else {
// 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat // 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat
setEditorState(BraftEditor.createEditorState(value)); setEditorState(BraftEditor.createEditorState(value));
}
}, [value]); }, [value]);
// 获取HTML // 获取HTML
const getHtml = () => { const getHtml = () => {
// 直接调用editorState.toHTML()来获取HTML格式的内容 // 直接调用editorState.toHTML()来获取HTML格式的内容
...@@ -57,8 +58,7 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef, ...@@ -57,8 +58,7 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef,
const handleEditorChange = (editorState: any) => { const handleEditorChange = (editorState: any) => {
setEditorState(editorState); setEditorState(editorState);
if (onChange) { if (onChange) {
const htmlContent = editorState.toHTML(); onChange(editorState);
onChange(editorState, htmlContent);
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment