react 富文本编辑中插入线上图片

本文探讨如何在React应用中的富文本编辑器里插入并显示来自线上的图片,结合相关技术进行详细说明。
摘要由CSDN通过智能技术生成
//清空
   clearContent = () => {
        this.setState({
            editorState: ContentUtils.clear(this.state.editorState)
        })
    }
//追加到后面
    insertText = () => {
        this.setState({
            editorState: ContentUtils.insertText(this.state.editorState, 'Hello World!')
        })
    }    
//发生变化事件
    handleChange = (editorState) => {
        console.log(editorState);
        this.setState({ editorState })
    }
//点击添加图片时调用 (insertMedias)
    tupian = (e) => {
        if (e.file.response != null) {
            let img = <img src={e.file.response.data.fileUrl}></img>
            console.log(img);
            this.setState({
                editorState: ContentUtils.insertMedias(this.state.editorState, [{
                    type: "IMAGE",
                    url: img.props.src,
                }],
                )
            })
        } el
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值