当草稿编辑器处于只读模式时,不会触发 onChange 事件。我想保留只读模式,但它必须触发 onChange 事件,以便我可以保存我的工作。
<Editor
readOnly={true}
onChange={this.onChange}
ref={(e) => { this.editor = e; }}
autoCapitalize="none"
autoComplete="off"
autoCorrect="off"
spellCheck={false}
/>
最佳答案
如下所示,您可以在编辑器更改或模糊事件上触发保存操作(但为了性能,我建议模糊):
const [editorState, setEditorState] = useState();
const [editable, setEditable]=useState(false);
const editorRef = useRef(null);
const onChange = (editorState) => {
setEditorState(editorState);
};
const onBlur = (state) => {
// convertToRaw from draft-js;
const contentState = convertToRaw(editorState.getCurrentContent());
// save contentState
};
return (
<Editor
editorState={editorState}
readOnly={!editable}
onChange={onChange}
onBlur={onBlur}
ref={editorRef}
autoCapitalize="none"
autoComplete="off"
autoCorrect="off"
spellCheck={false}
/>
)
关于javascript - 当草稿编辑器处于只读模式时 onChange 不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58687416/