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

  • 相关阅读:
    守护进程-锁-队列(生产者消费者模型)
    正则表达式不包含某个字符串写法
    正则表达式匹配不包含某些字符串的技巧
    08.参数估计_点估计
    07.编程理解中心极限定理
    05.编程理解小数和大数定律
    03.描述性统计代码
    02.描述统计 (descriptive statistics)
    oracle之三手工不完全恢复
    oracle之三手工完全恢复
  • 原文地址:https://www.cnblogs.com/xiaoyaoweb/p/10412917.html
Copyright © 2011-2022 走看看