vue中封装wang-editor组件和自定义音频组件

本文介绍如何在Vue项目中封装wang-editor富文本编辑器,并实现自定义的音频组件。通过封装,可以更好地集成到Vue应用中,提供便捷的文本编辑功能和音频插入能力。
摘要由CSDN通过智能技术生成

wang-editor.vue

<template>
<div>
  <div :id="params.id">
  </div>
  <Audio v-if="audioShow" @uploadAudio="uploadAudio"/>
</div>
</template>
<script>
import E from 'wangeditor'
import Audio from './audio.vue'
export default {
  name: 'wangEditor',
  components: {
    Audio
	},
  props: {
    id: {
      type: String,
      default: () => ''
    },
    content: {
      type: String,
      default: () => ''
    },
  },
  watch: {
    id (newVal) {
      this.params.id = newVal
    }
  },
  data() {
    return {
      localEditor: null,
      audioShow: false,
      params: {
        id: 'wang-editor', //富文本框ID
        menus: [
          'bold',
          'head',
          'link',
          'italic',
          'underline'
        ],
        customImgUpload: {
          flag: true, //是否自定义方法上传图片
          methods: {
            customUploadImg: (resultFiles, insertImgFn) => {
              console.log(resultFiles, insertImgFn, '插入图片')
              this.uploadFile('img', resultFiles, insertImgFn)
              // resultFiles 是 input 中选中的文件列表
              // insertImgFn 是获取图片 url 后,插入到编辑器的方法
              // 上传图片,返回结果,将图片插入到编辑器中
            }
          }
        },
        customVideoUpload: {
          flag: true, //是否自定义方法上传视频
          methods: {
            customUploadVideo: (resultFiles, insertVideoFn) => {
              console.log(resultFiles, insertVideoFn, '插入视频')
              this.uploadFile('video', resultFiles, insertVideoFn)
              // resultFiles 是 input 中选中的文件列表
              // insertVideoFn 是获取视频 url 后,插入到编辑器的方法
              // 上传视频,返回结果,将视频地址插入到编辑器中
              // insertVideoFn('https://touxianglogo.com/img/3.36eb1cce.jpg')
            }
          }
        },
        params: {
          focus: false, //自动focus
          placeholder: '请输入正文...', //placeholder内容提示
          showMenuTooltips: true, //菜单栏提示
          menuTooltipPosition: 'down',
          excludeMenus: [
            //自定义程度比较
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值