簡體   English   中英

反應HTML編輯器(TinyMce)

[英]React HTML Editor (TinyMce)

我正在為React搜索HTML編輯器,但是因為我發現沒有什么工作正常(我只需要格式化文本h1,h2,h3,p,粗體和圖像[在base64中])

最后我決定使用Tiny Mce,效果很好。 但只有當頁面第一次打開時。 如果我再次訪問該頁面。 如果沒有瀏覽器關聯,則不會初始化tinymce。 你知道在這種情況下會發生什么反應事件。 到目前為止,這是我的小包裝器:

/** @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;

為了解決這個問題,我必須在卸載時刪除TinyMce實例。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM