• 契合 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

  • 相关阅读:
    LR 两种录制:html与url
    性能测试心得之一
    杂记
    基于 python 的接口测试框架
    POJ3579 Median
    洛谷P4035 [JSOI2008]球形空间产生器
    洛谷P2455 [SDOI2006]线性方程组
    POJ2393 Yogurt factory
    洛谷P3763 [TJOI2017]DNA
    洛谷P2234 [HNOI2002]营业额统计
  • 原文地址:https://www.cnblogs.com/xiaoyaoweb/p/10412917.html
Copyright © 2020-2023  润新知