react html编辑器,react使用 UEditor富文本编辑器

本文详细指导如何在React项目中导入并配置UEditor,包括下载、文件名修改、路径放置、组件编写和页面引用。重点讲解了如何设置初始化参数、监听事件及内容回调,为开发者提供了一套完整的富文本编辑器使用教程。
摘要由CSDN通过智能技术生成

将下载的压缩包打包后 把文件名改成 UEditor;

然后放在项目根目录的public文件夹下

然后在 public文件的index.html文件引入。要按顺序引入

然后在components文件夹下创建 Editor.js 组件

import React from 'react';

export default class Editor extends React.Component {

constructor(props) {

super(props)

this.state = {

id: this.props.id || null,

ueEditor: null

}

}

componentDidMount() {

var UE = window.UE;

let { id } = this.state;

if (id) {

try {

UE.delEditor(id);

} catch (error) { }

let ueEditor = UE.getEditor(id, {

autoHeightEnabled: true,

autoFloatEnabled: true,

//字体大小

'fontsize': [10, 11, 12, 14, 16, 18, 20, 24, 36, 48],

// 上传图片时后端提供的接口

serverUrl: '',

enableAutoSave: false,

// eslint-disable-next-line no-dupe-keys

autoHeightEnabled: false,

initialFrameHeight: this.props.height,

initialFrameWidth: '100%',

});

this.setState({ ueEditor });

//判断有没有默认值

ueEditor.ready((ueditr) => {

var value = this.props.value ? this.props.value : '

ueEditor.setContent(value);

});

//将文本回调回去

ueEditor.addListener('selectionchange', (type) => {

//console.log(ueEditor.getContent())

this.props.callback(ueEditor.getContent());

});

//清空富文本内容

//this.refs.ueditor.changeContent("");

}

}

render() {

let { id } = this.state;

return (

}

}

然后在需要的页面引入 Editor

打开页面,我们就可以看到  Editor富文本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值