react富文本使用

Version note: React 15.4.2+ and react-dom 15.4.2+ is required. Antd version at last 2.8.3 in your project is recommended.

版本号说明:react、react-dom 版本必须在15.4.2以上,Antd版本最好在2.8.3以上。

1,使用命令安装第三方模块

npm install react-lz-editor --save  或者 yarn add react-lz-editor 

2, 把模块引入到自己的项目中,然后根据模块提供的api方法进行设置,实例如下

renter(){

return (

<div>

<LzEditor
     active={true}
     importContent={this.state.rawContent} cbReceiver={this.receiveRaw} uploadConfig={uploadConfig} image={false} video={false} audio={false} convertFormat="raw"/>

</div>

)

}

3, api参考

配置项类型默认值说明
activeboolfalse有更新时是否刷新
importContentstring""编辑器显示内容
cbReceiverfunctionnull编辑器内容更新后的回调函数,此函数接受一个改动后的返回参数值
undoRedobooltrue是否启用撤销恢复功能,默认启用
removeStylebooltrue是否启用移除格式功能,默认启用
pasteNoStylebooltrue是否启用文本粘贴功能,默认启用
blockStylebooltrue是否启用段落样式设置功能(H1、列表、区段等),默认启用
alignmentbooltrue是否启用文本对齐设置功能,默认启用
inlineStylebooltrue是否启用文字样式设置功能(加粗、倾斜、下划线等),默认启用
colorbooltrue是否启用文字颜色设置功能,默认启用
imagebooltrue是否启用图片上传后插入功能,默认启用
videobooltrue是否启用视频上传后插入功能,默认启用
audiobooltrue是否启用音频上传后插入功能,默认启用
urlsbooltrue是否启用添加删除链接功能,默认启用
autoSavebooltrue是否启用自动保存功能,默认启用
fullScreenbooltrue是否启用全屏功能,默认启用
convertFormatstring"html"设置内容导入导出格式,支持html、markdown、raw三种格式,默认html
uploadConfigobjectnull启用媒体上传后插入功能时,上传参数配置对象(上传到七牛,无需配置uploadProps)
uploadPropsobjectnull自定义上传方法及上传设置(无需配置uploadConfig,同时配置uploadConfig和uploadProps,则uploadProps优先),API请参考Antd.Upload

转载于:https://www.cnblogs.com/LHH1314/p/8611469.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
React富文本编辑框可以使用第三方库来实现,其中比较常用的是`react-quill`和`draft-js`。 1. 使用`react-quill`: 首先,安装`react-quill`库: ``` npm install react-quill ``` 然后,导入必要的组件并创建一个富文本编辑框组件: ```jsx import ReactQuill from 'react-quill'; import 'react-quill/dist/quill.snow.css'; // 导入样式 const RichTextEditor = () => { return ( <ReactQuill theme="snow" /> ); }; export default RichTextEditor; ``` 最后,在你的页面中使用这个组件: ```jsx import React from 'react'; import RichTextEditor from './RichTextEditor'; const App = () => { return ( <div> <h1>React富文本编辑框</h1> <RichTextEditor /> </div> ); }; export default App; ``` 2. 使用`draft-js`: 首先,安装`draft-js`库: ``` npm install draft-js ``` 然后,导入必要的组件并创建一个富文本编辑框组件: ```jsx import { Editor, EditorState } from 'draft-js'; import 'draft-js/dist/Draft.css'; // 导入样式 const RichTextEditor = () => { const [editorState, setEditorState] = useState(() => EditorState.createEmpty()); const handleChange = (newEditorState) => { setEditorState(newEditorState); }; return ( <Editor editorState={editorState} onChange={handleChange} /> ); }; export default RichTextEditor; ``` 最后,在你的页面中使用这个组件: ```jsx import React from 'react'; import RichTextEditor from './RichTextEditor'; const App = () => { return ( <div> <h1>React富文本编辑框</h1> <RichTextEditor /> </div> ); }; export default App; ``` 以上是两种常见的React富文本编辑框的实现方法,你可以根据自己的需求选择适合的库和组件来使用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值