import '@wangeditor/editor/dist/css/style.css'; // 引入 css import { useState, useEffect } from 'react'; import { Editor, Toolbar } from '@wangeditor/editor-for-react'; import type { IDomEditor, IEditorConfig, IToolbarConfig } from '@wangeditor/editor'; function MyEditor(props: any) { const { data } = props; // editor 实例 const [editor, setEditor] = useState(null); // 编辑器内容 const [html, setHtml] = useState(''); useEffect(() => { setHtml(data); }, []); // 工具栏配置 const toolbarConfig: Partial = {}; // 编辑器配置 const editorConfig: Partial = { placeholder: '请输入内容...', }; // 及时销毁 editor ,重要! useEffect(() => { return () => { if (editor == null) return; editor.destroy(); setEditor(null); }; }, [editor]); return ( <>
setHtml(el.getHtml())} mode="default" style={{ height: '300px', overflowY: 'hidden' }} />
); } export default MyEditor;