Vue3使用WangEditor编辑器

WangEditor的基本使用,图片上传功能
没详细讲解,只是做个记录。

Componets 下定义 WangEditor.vue 文件

<template>
    <div style="border: 1px solid #ccc;">
        <Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :defaultConfig="toolbarConfig" mode="default" />
        <Editor :style="{ 'height': height + 'px', 'overflow': 'hidden' }" v-model="newValue" :defaultConfig="editorConfig"
            mode="default" @onCreated="handleCreated" />
    </div>
</template>

<script setup>
import {
      defineProps, computed, shallowRef, defineEmits } from 'vue'
import {
      Editor, Toolbar } from '@wangeditor/editor-for-vue'
import Cookies from 'js-cookie'
import '@wangeditor/editor/dist/css/style.css' // 引入 css 

const props = defineProps({
     
    // 父组件 v-model 绑定的值
    modelValue: {
     
        type: String
    },
    // 富文本的高
    height: {
     
        type: [Number, String],
        default: 400
    }
})

const editorRef = shallowRef()

const emit = defineEmits(['update:modelValue'])

const toolbarConfig = {
     }

const editorConfig = {
      placeholder: '请输入内容...', MENU_CONF: {
     } }

editorConfig.MENU_CONF['uploadImage'] = {
     
    // 上传图片
    fieldName: 'file',
    // headers头部 需要添加不需要删掉
    headers: {
     
        Authorization: Cookies.get('Token'),
        ContentType: 'application/json;charset=utf-8'
    },
    // 图片上传的路径
    server: import.meta.env.VITE_APP_BASE_API + '/image/upload',
    // 图片上传返回的数据
    customInsert(res, insertFn) {
     
        let src = import.meta.env.VITE_APP_BASE_API + res.data.url // 有的会返回带域名的路径也有不带的根据自己的实际情况
        insertFn(src)
    },
}

editorConfig.MENU_CONF['uploadVideo'] = {
     

}

const newValue = computed({
     
    get() {
     
        return props.modelValue
    },
    set(value) {
     
        emit('update:modelValue', value)
    }
})

const handleCreated = (editor) => {
     
    editorRef.value = editor // 记录 editor 实例,重要!
    // console.log(editor.getAllMenuKeys()) // 这里输出可以看到 富文本中所有的功能
}

</script>

<style lang="scss" scoped></style>

相关推荐

  1. Vue3使用WangEditor编辑器

    2023-12-31 14:04:02       63 阅读
  2. vue3下富文本编辑器@wangeditor的一些配置

    2023-12-31 14:04:02       52 阅读
  3. vue3+wangeditor实现富文本

    2023-12-31 14:04:02       42 阅读
  4. vue2使用富文本wangeditor

    2023-12-31 14:04:02       58 阅读
  5. vue-codeirror编辑器vue3中的使用

    2023-12-31 14:04:02       31 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-31 14:04:02       91 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-31 14:04:02       97 阅读
  3. 在Django里面运行非项目文件

    2023-12-31 14:04:02       78 阅读
  4. Python语言-面向对象

    2023-12-31 14:04:02       88 阅读

热门阅读

  1. Linux cat 命令

    2023-12-31 14:04:02       63 阅读
  2. 【WPF.NET开发】预览事件

    2023-12-31 14:04:02       56 阅读
  3. 关于WPF MVVM 的详细使用过程以及注意的问题

    2023-12-31 14:04:02       48 阅读
  4. pd.groupby的2种用法

    2023-12-31 14:04:02       57 阅读
  5. Linux Shell 013-文本列过滤工具cut

    2023-12-31 14:04:02       66 阅读
  6. 09.kubernetes 部署calico / flannel网络插件

    2023-12-31 14:04:02       58 阅读
  7. MySql 第三方工具SQL Sugar

    2023-12-31 14:04:02       53 阅读
  8. 解密垃圾邮件分类:基于SVM的数据挖掘项目

    2023-12-31 14:04:02       66 阅读
  9. BFC(解决高度塌陷的问题)

    2023-12-31 14:04:02       48 阅读