Commit 8651474a authored by 满振华's avatar 满振华

修改子组件

parent 57facb12
......@@ -38,13 +38,14 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef,
const [editorState, setEditorState] = useState(BraftEditor.createEditorState(null));
const [percent, setPercent] = useState(0); // 进度条
const previewRef = useRef(null);
useEffect(() => {
if (value && typeof value === 'object') { // 不做转换
setEditorState(value)
} else {
// 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat
setEditorState(BraftEditor.createEditorState(value));
}
}, [value]);
// 获取HTML
const getHtml = () => {
// 直接调用editorState.toHTML()来获取HTML格式的内容
......@@ -57,8 +58,7 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef,
const handleEditorChange = (editorState: any) => {
setEditorState(editorState);
if (onChange) {
const htmlContent = editorState.toHTML();
onChange(editorState, htmlContent);
onChange(editorState);
}
};
......
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