vue使用百度富文本

🔥博客主页破浪前进

🔖系列专栏VueReactPHP

❤️感谢大家点赞👍收藏⭐评论✍️


1、下载UEditor

链接已放到文章中了

2、上传到项目目录中

一般上传到public下,方便到时候打包进去,以免出现线上版本无法使用等问题

3、安装vue-ueditor-wrap最新3.x版本

css 复制代码
npm i vue-ueditor-wrap@next

4、在main.js中引入并使用

javascript 复制代码
import VueUeditorWrap from 'vue-ueditor-wrap'
createApp(App).use(VueUeditorWrap).mount('#app')

5、使用

html 复制代码
<template>
  <div>
    <vue-ueditor-wrap v-model="msg" :config="myConfig"></vue-ueditor-wrap>
    <div v-html="msg"></div>
  </div>
</template>
<script>
import { ref } from 'vue'
export default {
  setup() {
    let msg = ref('<h2><img src="//i2.wp.com/img.baidu.com/hi/jx2/j_0003.gif"/>Vue + UEditor + v-model双向绑定</h2>')
    let myConfig = {
      // 编辑器不自动被内容撑高
      autoHeightEnabled: false,
      // 初始容器高度
      initialFrameHeight: 450,
      // 初始容器宽度
      initialFrameWidth: '100%',
      // 上传文件接口
      serverUrl: '/api/upload/file',
      // UEditor 资源文件的存放路径,如果你使用的是 vue-cli 生成的项目,通常不需要设置该选项,vue-ueditor-wrap 会自动处理常见的情况
      UEDITOR_HOME_URL: '/ueditor/'
    }
    return {
      myConfig,
      msg
    }
  }
}
</script>

6、配置代理,否则会报错且无法使用上传图片等功能,下篇博客会说的

相关推荐
_Kayo_19 小时前
TypeScript 学习笔记2
前端·javascript·typescript
海纳百川本尊7606419 小时前
Flutter框架核心原理深度解析
前端
Shaneyxs19 小时前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(12)
前端
ss27319 小时前
SpringBoot+vue养老院运营管理系统
vue.js·spring boot·后端
渔_19 小时前
uni-app 图片预览 + 长按保存,超实用!
前端
八哥程序员19 小时前
从DOM结构到布局流:display: content的深度解析与实战应用
前端·css
Shaneyxs19 小时前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(07)
前端
Shaneyxs19 小时前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(10)
前端
Shaneyxs19 小时前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(05)
前端