Vue集成ueditor

本文详细介绍了如何封装和配置富文本编辑器UEditor,包括设置appid、appkey、token和文件预览地址,以及针对图片、附件、视频和涂鸦上传的接口修改,确保与项目统一并支持文件上传验证。此外,还提供了编辑器内容的设置和获取方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 封装组件

<template>

  <div>

    <script id="editor" type="text/plain" style="height:300px;" />

  </div>

</template>

<script>

import '../../static/ueditor/ueditor.config.js'

import '../../static/ueditor/ueditor.all.js'

import '../../static/ueditor/lang/zh-cn/zh-cn.js'

import '../../static/ueditor/ueditor.parse.min.js'

import constants from '@/utils/constants'

import { getToken } from '@/utils/auth'

export default {

  name: 'UE',

  props: {

    catalog: {

      type: String,

      required: true

    },

    // 默认的初始内容

    defaultMsg: {

      type: String,

      default: ''

    },

    // 配置项,工具栏

    config: {

      type: Object,

      default: () => {

        return {}

      }

    }

  },

  data() {

    return {

      editor: null

    }

  },

  mounted() {

    const _this = this

    this.config.chishipConfig = {

      headers: {

        'App-Key': this.constants.APP_KEY,

        'App-Id': this.constants.APP_ID,

        'Access-Token': getToken()

      },

      fileViewServer: this.global.getFileView('{UUID}')

}

this.config.serverUrl = process.env.BASE_API + this.constants.UPMS + 'ue'

    // eslint-disable-next-line no-undef

    this.editor = UE.getEditor('editor', this.config)

    this.editor.addListener('ready', function() {

      _this.editor.setContent(_this.defaultMsg)

    })

    // eslint-disable-next-line no-undef

    if (!UE.Editor.prototype._bkGetActionUrl) {

      // eslint-disable-next-line no-undef

      UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl

      // eslint-disable-next-line no-undef

      UE.Editor.prototype.getActionUrl = function(action) {

        console.log(action)

        if (action === 'uploadimage') {

          return (

            process.env.BASE_API + constants.DOCS + 'file/ueUpload?catalogId=' + _this.catalog

          )

        } else if

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智舰网络工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值