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、配置代理,否则会报错且无法使用上传图片等功能,下篇博客会说的

相关推荐
Cloud云工场科技18 小时前
“人工智能 +” 创新大会签约落定,云工场科技与沐曦、中国移动等企业携算力服务助力潍坊转型发展
百度
PineappleCoder1 天前
性能数据别再瞎轮询了!PerformanceObserver 异步捕获 LCP/CLS,不卡主线程
前端·性能优化
新程记1 天前
2025年,上海CAIE认证报考指南:把握AI机遇的实用起点
人工智能·百度
PineappleCoder1 天前
告别字体闪烁 / 首屏卡顿!preload 让关键资源 “高优先级” 提前到
前端·性能优化
m0_471199631 天前
【vue】通俗详解package-lock文件的作用
前端·javascript·vue.js
GIS之路1 天前
GDAL 读取KML数据
前端
今天不要写bug1 天前
vue项目基于vue-cropper实现图片裁剪与图片压缩
前端·javascript·vue.js·typescript
用户47949283569151 天前
记住这张时间线图,你再也不会乱用 useEffect / useLayoutEffect
前端·react.js
汝生淮南吾在北1 天前
SpringBoot+Vue养老院管理系统
vue.js·spring boot·后端·毕业设计·毕设