react项目中集成 braft-editor富文本编辑

本文介绍了如何在React项目中集成Braft-Editor,包括安装步骤和富文本编辑器的完整代码示例。
摘要由CSDN通过智能技术生成

1.首先安装编辑器

cnpm i braft-editor --save

2.富文本相关全部代码

import React from 'react'
import {
    Form, Select, InputNumber, Switch, Radio,
    Slider, Button, Upload, Icon, Rate, Checkbox,
    Row, Col, Input, DatePicker, Modal, Card, Spin, message
} from 'antd';
import './yunyingissue.scss'
import { postfn, getfn, Normal } from '../../../../server'
import moment from 'moment';
import axios from 'axios'
import Regex from 'regex'
// 富文本
import BraftEditor, { EditorState } from 'braft-editor';
// 引入编辑器样式
import 'braft-editor/dist/index.css';
// 引入七牛
import * as qiniu from 'qiniu-js';
// 日期选择设置为中文
import { LocaleProvider } from 'antd';
import zh_CN from 'antd/lib/locale-provider/zh_CN';
import 'moment/locale/zh-cn';
const { Option } = Select;
const { MonthPicker, RangePicker } = DatePicker;





class Demo extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            // 富文本
            // 创建一个空的editorState作为初始值
            editorState: EditorState.createFrom(''),
            htmlDom: "",
            token: "",
            urlKey: '',//七牛返回来的key
            qiniuBaseUrl: '',//区别正式和测试环境
        }
        // 富文本相关
        this.upImgs = this.upImgs.bind(this);
    }
   
    // 富文本
    submitContent = async () => {
        // 在编辑器获得焦点时按下ctrl+s会执行
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会尽力回答你的问题。首先,GG-Editor 是一个基于 G6 实现的图形编辑器,它提供了一系列编辑和展示流程图、拓扑图、类关系图等的功能。如果你想在React项目引入GG-Editor,可以按照以下步骤进行: 1. 安装 GG-Editor 你可以通过 npm 或者 yarn 安装 GG-Editor,具体命令如下: ``` npm install gg-editor --save ``` 或者 ``` yarn add gg-editor ``` 2. 引入 GG-Editor 在你的 React 项目,可以通过以下方式引入 GG-Editor: ```javascript import React from 'react'; import GGEditor, { Flow } from 'gg-editor'; const YourComponent = () => { return ( <GGEditor> <Flow /> </GGEditor> ); }; export default YourComponent; ``` 在上面的代码,我们使用了 GGEditor 和 Flow 组件,其 GGEditor 是 GG-Editor 的核心组件,可以包含多个编辑器实例,而 Flow 是一个基于 G6 实现的流程图组件,用于展示和编辑流程图。 3. 配置 GG-Editor 你可以在 GGEditor 组件上通过 props 进行一些配置,例如: ```javascript <GGEditor className="editor" style={{ width: '100%', height: '100%' }}> <Flow /> </GGEditor> ``` 4. 编辑流程图 在 GG-Editor ,你可以使用 Flow 组件来编辑流程图。例如,下面的代码演示了如何在 Flow 组件添加一个节点: ```javascript import React from 'react'; import GGEditor, { Flow } from 'gg-editor'; const YourComponent = () => { const data = { nodes: [ { id: 'node1', x: 50, y: 50, label: 'Node 1', }, ], edges: [], }; return ( <GGEditor className="editor" style={{ width: '100%', height: '100%' }}> <Flow data={data} /> </GGEditor> ); }; export default YourComponent; ``` 在上面的代码,我们通过 data 属性传入了一个包含一个节点的数据对象,然后在 Flow 组件展示了这个流程图。 希望这些步骤能够帮助你在 React 项目引入 GG-Editor。如果你有任何问题,请随时提出!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值