有没有大神遇到过 tower的开源编辑器simditor使用了 simditor-markdown 扩展就无法监听事件了react, jsx: componentDidMount () { this.initEditor() } initEditor = () => { this.editor = new Simditor({ textarea: this.textArea, markdown: true, toolbar: ['title', 'bold', 'italic', 'underline', 'code', 'blockquote', '|', 'ol', 'ul', '|', 'markdown'] }) this.editor.setValue(marked(this.props.content)) this.editor.on('valuechanged', (e, src) => { this.props.onTextChange(toMarkdown(this.editor.getValue())) }) }Tag:<textarea ref={textarea => (this.textArea = textarea)} />拜托了.
1 回答

慕尼黑8549860
TA贡献1818条经验 获得超11个赞
解决方法: 覆写源码的获取value, 包装标签方法(继续didMount下):
const editorNote = this simditorMarkdown.prototype._convert = function () { const text = this.textarea.val(); editorNote.props.onTextChange(text) const markdownText = marked(text); // textarea this.editor.textarea.val(markdownText); // tag this.editor.body.html(markdownText); // 包了层div this.editor.formatter.format(); return this.editor.formatter.decorate(); }; this.editor.setValue(marked(this.props.content))
另外分享下: 表单组件建议用onchange,今天有个上传组件手贱写成了onClick, 刚开始以为state没有改变的原因,后来注意到了.
添加回答
举报
0/150
提交
取消