zoukankan      html  css  js  c++  java
  • 契合 antd的富文本编辑器braft-editor 使用实例

    import '../../../../braft-editor/dist/index.css'
    import React from 'react'
    import BraftEditor from 'braft-editor'
    
    export default class Editor1 extends React.Component {
    	state = {
    		// 创建一个空的editorState作为初始值
    		editorState: BraftEditor.createEditorState(null)
    	}
    
    	async componentDidMount() {
    		var _self = this
    		this.setState({
    			editorState: BraftEditor.createEditorState(this.props.val)
    		})
    	}
    	render() {
    		const { editorState } = this.state
    		const controls = [
    			'undo', 'redo', 'separator',
    			'font-size', 'line-height', 'letter-spacing', 'separator',
    			// 'text-color', 'bold', 'italic', 'underline', 'strike-through', 'separator',
    			// 'superscript', 'subscript', 'remove-styles', 'emoji', 'separator', 'text-indent', 'text-align', 'separator',
    			// 'headings', 'list-ul', 'list-ol', 'blockquote', 'code', 'separator',
    			// 'link', 'separator', 'hr', 'separator',
    			// 'media', 'separator',
    			// 'clear'
    		]
    
    		return (
    			<div style={{  this.props.width, height: this.props.height || '100px', display: 'inline-block', margin: "40px 10px 10px -115px", lineHeight: '24px' }} >
    				<BraftEditor
    					defaultValue={this.props.val}
    					value={editorState}
    					onChange={this.handleChange}
    					controls={controls}
    					onSave={this.submitContent}
    				/>
    			</div>
    
    		)
    	}
    	handleChange = (editorState) => {
    		const htmlString = editorState.toHTML()
    		this.setState({ editorState: editorState }, () => {
    			this.props.onChange(htmlString)
    		})
    	}
    }
    
    # 使用npm安装
    npm install braft-editor --save

     还有一个index.css 引入地址 :https://github.com/margox/braft-editor

  • 相关阅读:
    eclipse 中文乱码
    为linux下ibus输入法添加搜狗词库
    汇编语言数据类型与声明
    linux下访问小米手机sd卡
    ubuntu linux下真机调试android程序
    Rhythmbox mp3音乐乱码的解决办法
    初学python线程(转)
    linux下安装安装BeautifulSoup
    django模板过滤器
    django使用静态文件
  • 原文地址:https://www.cnblogs.com/xiaoyaoweb/p/10412917.html
Copyright © 2011-2022 走看看