vxe-form 表单中使用渲染 wangEditor 富文本组件,配置式渲染

官网文档:https://vxeui.com

在vue使用表单的时候,经常需要用到富文本组件,wangEditor是原生的组件,要在 vue 中使用需要封装一下。

表单中使用

安装 vxe 4.x 版本,具体看官网
在 vxe-from 中,渲染任何控件,只需在 itemRender 指定控件 name 就可以了。

npm install @vxe-ui/plugin-render-wangeditor@4.0.2

在 index.html 中引入wangEditor就可以了。

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@wangeditor/editor@5.1.23/dist/css/style.css">

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@wangeditor/editor@5.1.23/dist/index.js"></script>
import { VxeUI } from 'vxe-pc-ui'
import VxeUIPluginRenderWangEditor, { WangEditor } from '@vxe-ui/plugin-render-wangeditor'
import '@vxe-ui/plugin-render-wangeditor/dist/style.css'

VXETable.use(VxeUIPluginRenderWangEditor, {
  // 自定义上传图片方法
  uploadImageMethod ({ file }) {
    const formData = new FormData()
    formData.append('file', file)
    return axios.post('/api/pub/upload/single', formData).then((res) => {
      // { url: '' }
      return {
        ...res.data
      }
    })
  },
  // 自定义上传视频方法
  uploadVideoMethod ({ file }) {
    const formData = new FormData()
    formData.append('file', file)
    return axios.post('/api/pub/upload/single', formData).then((res) => {
      // { url: '' }
      return {
        ...res.data
      }
    })
  }
})

// (可选组件)如果全局安装了,就可以在 vue 文件模板中直接使用该组件
app.use(WangEditor)

在这里插入图片描述

<template>
  <div>
    <vxe-form v-bind="formOptions" >
      <template #action>
        <vxe-button type="reset">重置</vxe-button>
        <vxe-button type="submit" status="primary">提交</vxe-button>
      </template>
    </vxe-form>
  </div>
</template>

<script setup>
import { reactive } from 'vue'

const formOptions = reactive({
  titleWidth: 120,
  data: {
    name: 'test1',
    remark: ''
  },
  items: [
    { field: 'name', title: '名称', span: 24, itemRender: { name: 'VxeInput' } },
    { field: 'remark', title: '富文本', span: 24, itemRender: { name: 'WangEditor' } },
    { align: 'center', span: 24, slots: { default: 'action' } }
  ]
})
</script>

试一下 ctrl + v 粘贴截图,会自动调用上传接口,转成服务端 url。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值