1. 程式人生 > >react ant-design 使用ueditor

react ant-design 使用ueditor

1.頁面引入

    <script type="text/javascript" src="http://localhost:8080/HBBKCOM/content/chajian/ueditor/editor_config.js"></script>
    <script type="text/javascript" src="http://localhost:8080/HBBKCOM/content/chajian/ueditor/editor_api.js"></script>

2.頁面引入了js  但是UE變數不能直接使用 可以寫段js來繫結一下 如

  <script type="text/javascript">
      Date.prototype.UE=UE ;

</script>

3.自定義控制元件ueditor.js

import React,{ Component } from 'react'; 
class Ueditor extends Component {
    componentDidMount(){
        var UE=new Date().UE;
        try{UE.getEditor(this.props.id).destroy();}catch(err){}//再次初始化有問題  要銷燬原來的
        var editor = UE.getEditor(this.props.id, {
             lang:"zh-cn" ,initialFrameHeight: this.props.height , initialFrameWidth: '100%'
        });
        var me = this;
        editor.ready( function( ueditor ) {
            var value = me.props.value?me.props.value:'<p></p>';
            editor.setContent(value);
        });
    }
    render(){
        return (
            <div id={this.props.id}></div>
        )
    }
}
export default Ueditor;

使用

<Ueditor value="" id="content" height="200" />