#yyds干货盘点 【React工作记录二十九】react中使用的富文本编辑器braft-editor使用

简介: #yyds干货盘点 【React工作记录二十九】react中使用的富文本编辑器braft-editor使用

前言

我是歌谣 我有个兄弟 巅峰的时候排名c站总榜19 叫前端小歌谣 曾经我花了三年的时间创作了他 现在我要用五年的时间超越他 今天又是接近兄弟的一天人生难免坎坷 大不了从头再来 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷


导语

歌谣 歌谣 项目中需要使用富文本的编辑器 你有什么推荐吗


image.png


编辑


image.png


编辑


解决思路

第一步安装依赖


#使用yarn安装     yarn add braft-editor
 #使用npm安装    npm install braft-editor --save


第二步 封装子组件

import React, { Component } from 'react'
import BraftEditor from 'braft-editor';
import 'braft-editor/dist/index.css';
//音频接口方法
import { xxxxx } from '@/services/common/upload';
class BaseRichText extends Component {
  myUploadFn = async (parame) => {
    const { dispatch, handleFetchUrl } = this.props;
    const formData = new FormData();
    formData.append('file', parame.file);
    formData.append('fileCode', 'PIC');
    const res = await xxxxx(formData);
    parame.success({
      url: res.data,
      meta: {
        loop: false, // 指定音视频是否循环播放
        autoPlay: false, // 指定音视频是否自动播放
        controls: false, // 指定音视频是否显示控制栏
        // poster: 'http://xxx/xx.png', // 指定视频播放器的封面
      }
    })
  }
  render() {
    const { editorState, handleEditorChange, height = 640, 
style, ...reset } = this.props;
    return (
      <BraftEditor
        value={editorState}
        onChange={handleEditorChange}
        style={style}
        contentStyle={{ height, boxShadow: 'inset 0 1px 3px
 rgba(0,0,0,.1)' }}
        {...reset}
        media={{ uploadFn: this.myUploadFn }}
      />
    );
  }
}
export default BaseRichText;

第三步 引入


<BaseRichText height={360} handleEditorChange={this.handleEditorChange} />




第四部 回调


handleEditorChange = (editorState) => {
    console.log(editorState, 'editorState');
    this.setState({ activityRule: editorState });
  };




总结

要点1 处理数据分别用xxx.toHtml()转化和BraftEditor.createEditorState(xxxx)反转化


要点2 回调可以实时返回当前值 及时存储



相关文章
|
8月前
|
资源调度 前端开发
React富文本编辑器wangEditor
React富文本编辑器wangEditor
150 0
|
3月前
|
JavaScript 前端开发
在 Vue 2 中安装和使用 mavon-editor富文本编辑器
在 Vue 2 中安装和使用 mavon-editor富文本编辑器
68 0
|
4月前
|
资源调度 前端开发
React富文本编辑器wangEditor
React富文本编辑器wangEditor
|
4月前
|
存储 前端开发 JavaScript
医院电子病历编辑器,EMRE(EMR Editor)源码
医院电子病历编辑器,EMRE(EMR Editor)源码
66 0
|
4月前
|
缓存 资源调度 小程序
微信小程序(二十五)微信小程序富文本编辑器editor上传图片
一般在做网站开发的时候,最开始使用的一般都是百度的ueditor,但是这个玩意好久不更新了,功能到时够用,就是UI以及其他的一些套件的视觉效果稍差。
81 0
|
7月前
UE中创建异步任务编辑器工具(Editor Utility Tasks)
UE中创建异步任务编辑器工具(Editor Utility Tasks)
111 0
UE中创建异步任务编辑器工具(Editor Utility Tasks)
|
7月前
|
编解码
UE中使用Editor Utility Widget创建编辑器工具
UE中使用Editor Utility Widget创建编辑器工具
193 0
UE中使用Editor Utility Widget创建编辑器工具
|
10月前
|
存储 前端开发
react中使用的富文本编辑器braft-editor使用
react中使用的富文本编辑器braft-editor使用
226 0
|
IDE 安全 前端开发
Win11系统下安装编辑器之神(The God of Editor)Vim并且构建Python生态开发环境
众神殿内,依次坐着Editplus、Atom、Sublime、Vscode、JetBrains家族、Comodo等等一众编辑器界的大佬们,偌大的殿堂内几无立锥之地,然而在殿内的金漆雕龙宝座上,端坐着一位睥睨众生的王者,那就是被称之为编辑器之神的Vim,作为一个有着30余年历史的老牌神器,没有任何编辑器可以和它媲美,其时江湖有云:神编Vim不会玩,纵称大神也枉然。Vim在 1976 年发布,奉行 Unix 传统的“Do one thing and do it well”哲学,每个程序只做一件事但求做到最好,通过程序之间的配合得到强大的功能,其两种模式(Normal/Insert) 的玄妙变换,幻
Win11系统下安装编辑器之神(The God of Editor)Vim并且构建Python生态开发环境
|
存储 图形学 索引
Unity 编辑器开发实战【Custom Editor】- FSM Editor
Unity 编辑器开发实战【Custom Editor】- FSM Editor
257 0
Unity 编辑器开发实战【Custom Editor】- FSM Editor