uso51984 / react-ueditor

demo
http://uso.oschina.io/react-ueditor-demo/
73 stars 16 forks source link

频繁调用控件会出现这个错误:TypeError: Cannot set property 'innerHTML' of undefined #4

Closed EvanJonQiu closed 5 years ago

EvanJonQiu commented 5 years ago

用react-ueditor进行新闻编辑,当在列表中,点击不同得新闻条目进行编辑,会出现下面的错误。

TypeError: Cannot set property 'innerHTML' of undefined UE.Editor.setContent http://localhost:8000/public/lib/ueditor1_4_3_3-utf8-jsp/utf8-jsp/ueditor.all.js:7347:31 RichText.componentWillReceiveProps C:/Users/xxxx/Documents/esri/sources/react/xxxx/node_modules/react-ueditor-wrap/lib/richtext.js:131 128 | var value = _ref.value; 129 | 130 | if (value !== this.props.value && this.editor) {

131 | this.editor.setContent(value); 132 | } 133 | } 134 | }, { View compiled callComponentWillReceiveProps C:/Users/xxx/Documents/esri/sources/react/xxxx/node_modules/react-dom/cjs/react-dom.development.js:12564 12561 | var oldState = instance.state; 12562 | startPhaseTimer(workInProgress, 'componentWillReceiveProps'); 12563 | if (typeof instance.componentWillReceiveProps === 'function') { 12564 | instance.componentWillReceiveProps(newProps, nextContext); 12565 | } 12566 | if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') { 12567 | instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);

uso51984 commented 5 years ago

@EvanJonQiu 能否把你是如何调用代码的贴出来看看

EvanJonQiu commented 5 years ago

<FormItem style={{width: '100%', height: '100%'}}> <RcUeditor ueditorUrl={window.origin+"/lib/utf8-php/ueditor.all.js"} ueditorConfigUrl={window.origin+"/lib/utf8-php/ueditor.config.js"} editorConfig={editorConfig} style={{width: '100%', height: 600}} onChange={this.handleChange} value={value} /> 这是调用代码。

EvanJonQiu commented 5 years ago

1 修改了接口,增加setEditor属性

<RcUeditor ueditorUrl={window.origin+"/lib/utf8-php/ueditor.all.js"}
                         ueditorConfigUrl={window.origin+"/lib/utf8-php/ueditor.config.js"}
                         editorConfig={editorConfig}
                         style={{width: '100%', height: 600}}
                         onChange={this.handleChange}
                         value={value}
                         setEditor={this.setEditor}

2 构造函数我修改了如下内容:

//var editor = new UE.ui.Editor(conf);
      var editor = new UE.getEditor(_this.uuid, conf);
      _this.editor = editor;

      editor.addListener('blur contentChange', function () {
        _this.onChange();
      });
      /*
      editor.render(target);
      editor.ready(function () {
        editor.setContent(value);
      });
      */
      editor.ready(function (param) {
        if (!param) {
          UE.delEditor(_this.uuid);
          _this.initRichText();
        } else {
          if (editor.body) {
            _this.props.setEditor(editor);
          }
        }
      });
    };

3 去掉componentWillReceiveProps

  }, {
    key: 'componentWillUnmount',
    value: function componentWillUnmount() {
      if (!this.editor) return;
      this.editor.destroy();
    }
  },/* {
    key: 'componentWillReceiveProps',
    value: function componentWillReceiveProps(_ref) {
      var value = _ref.value;

      if (value !== this.props.value && this.editor) {
        this.editor.setContent(value);
      }
    }
  },*/ {
    key: 'loadUEditorScript',

4 将内容更新放到调用者的componentWillReceiveProps当中

componentDidUpdate(prevProps, prevState, snapshot) {
    if (this.state.editor) {
      let value = this.state.editor.getContent();
      if (this.state.htmlContent !== "" && value === '') {
        this.state.editor.setContent(this.state.htmlContent);
      }
    }
  }
uso51984 commented 5 years ago

@EvanJonQiu 没看出什么问题,注释的编译后的代码? 看你加我微信交流下? chenjianbin519846538

LbhFront-end commented 5 years ago

可以说说最后怎么解决的吗,遇到同样的问题

EvanJonQiu commented 5 years ago

可以说说最后怎么解决的吗,遇到同样的问题

我直接修改的代码,上面有。

LbhFront-end commented 5 years ago

可以说说最后怎么解决的吗,遇到同样的问题

我直接修改的代码,上面有。

好的,谢谢 我看看

xzdashen commented 5 years ago

我是按照上面 修改的dist目录下面的 react-ueditor.js文件,然后刷新页面 还是会出现 Cannot set property 'innerHTML' of undefined