import React,{Component } from 'react';
import { Card, Button, Table, Form, Select,Modal, message } from 'antd';
import { Wrap } from './style';
// 富文本的 內容數據值
import { EditorState } from 'draft-js';
// 組件化標籤
import { Editor } from 'react-draft-wysiwyg';
// 默認編輯器的css樣式
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';
// 設置 成爲 html標籤
import draftjs from 'draftjs-to-html';javascript
export default class EditorDemo extends Component{css
state={}html
// 默認提交動做
onEditorStateChange = (editorState) => {
this.setState({
editorState,
});
}
// 修改提交動做
onEditorChange: Function = (contentState) => {
this.setState({
contentState,
});
};
// 清空文本編輯器
handleClearContent = ()=>{
this.setState({
editorState:''
})
}
// 獲取 時時修改後的 內容值 轉換爲HTML
handleGetText = ()=>{
this.setState({
showEditorText:true
})
}java
render(){
const {editorState} = this.state;
return (
<Wrap>
<Card title="操做">
<Button type="primary" onClick={this.handleClearContent}>清空內容</Button>
<Button type="primary" onClick={this.handleGetText} >獲取Html內容</Button>
</Card>
<Card title="富文本編輯器">
<Editor
editorState = { editorState }
onContentStateChange = {this.onEditorChange}
onEditorStateChange = { this.onEditorStateChange }react
/>
</Card>
<Modal
title='富文本'
visible={this.state.showEditorText}
onCancel={()=>{
this.setState({
showEditorText:false
})
}}
footer={null}
>
{draftjs(this.state.contentState)}
</Modal>
</Wrap>
);
}
}數據庫
------------------------------------------------------------------------------------------------------------------------------------------------------antd
字符串轉移爲html代碼 (編輯器寫入一段帶HTML格式的存入了數據庫,數據庫拿出來用這個轉爲HTML代碼)編輯器
dangerouslySetInnerHTML={{__HTML:this.props.String}} |