简体   繁体   English

反应HTML编辑器(TinyMce)

[英]React HTML Editor (TinyMce)

I was searching for an HTML Editor for React, but since I found nothing that works fine (I just need to format Text h1, h2, h3, p, bold and images [in base64]) 我正在为React搜索HTML编辑器,但是因为我发现没有什么工作正常(我只需要格式化文本h1,h2,h3,p,粗体和图像[在base64中])

At the end I decided to use Tiny Mce, which works fine. 最后我决定使用Tiny Mce,效果很好。 But only when the page gets opened for the first time. 但只有当页面第一次打开时。 If I get to that page again. 如果我再次访问该页面。 Without a browser relaod, then tinymce is not initialized. 如果没有浏览器关联,则不会初始化tinymce。 Do you know what react event will be triggered in such a situation. 你知道在这种情况下会发生什么反应事件。 Here is my little wrapper so far: 到目前为止,这是我的小包装器:

/** @jsx React.DOM */
var React = require('react');

var TinyMceEditor = React.createClass({
    componentDidMount: function() {
        var that = this;
        tinymce.init({
            selector: "textarea.tiny-mce-editor",
            setup : function(editor) {
                editor.on('change', function(e) {
                    that.props.onChange(editor.getContent());
                });
            },
            plugins: [
                "lists link image charmap print preview anchor",
                "searchreplace code fullscreen",
                "insertdatetime media table contextmenu paste"
            ],
            toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
        });
        tinyMCE.get(that.props.lang + '-editor').setContent(that.props.html);
    },
    render:function(){
        return (
            <div>
                <textarea ref="text" className="tiny-mce-editor" id={this.props.lang + '-editor'} />
            </div>
        )
    }
});
module.exports = TinyMceEditor;

To fix this I had to delete the TinyMce instance when unmounting. 为了解决这个问题,我必须在卸载时删除TinyMce实例。

componentWillUnmount: function() {
    tinymce.remove('#' + this.props.lang + '-editor');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM