站在大佬的身旁之Ueditor百度富文本word图片转存问题解决

本文详细描述了如何在Vue项目中下载并配置Ueditor富文本编辑器,包括从百度网盘下载、在ueditor.config.js中设置服务器接口、在components中封装成组件以及在App.vue中使用。同时介绍了如何监听ready事件和获取/设置编辑器内容。
摘要由CSDN通过智能技术生成

下载Ueditor

链接: https://pan.baidu.com/s/1FkMM5yGKNhH7phRWJ0FcdA?pwd=wjy4

使用Ueditor

  1. 解压下载的Ueditor,放在项目的public下
    在这里插入图片描述
  2. 在ueditor.config.js中配置服务器统一请求接口路径,我使用的Java编写的接口
    在这里插入图片描述
  3. public下index.html引入ueditor相关js文件
    在这里插入图片描述
    <script type="text/javascript" charset="utf-8" src="./UEditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="./UEditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="./UEditor/lang/zh-cn/zh-cn.js"></script>   
  1. 封装成components组件
    components文件夹下创建Ueditor\index.vue
    index.vue内容如下
<template>
  <div>
    <script :id="randomId" type="text/plain" style="height: 300px;"></script>
  </div>
</template>

<script>

export default {
  name: 'UE',
  props: {
    value: {
      default: function () {
        return ''
      }
    }
  },
  data () {
    return {
      randomId: 'editor_' + Math.random() * 100000000000000000,
      // 编辑器实例
      instance: null,
      ready: false
    }
  },
  watch: {
    value: function (val) {
      if (val != null && this.ready) {
        // eslint-disable-next-line no-undef
        this.instance = UE.getEditor(this.randomId)
        this.instance.setContent(val)
      }
    }
  },
  mounted () {
    this.initEditor()
  },

  beforeDestroy () {
    if (this.instance !== null && this.instance.destroy) {
      this.instance.destroy()
    }
  },
  methods: {
    initEditor () {
      this.$nextTick(() => {
        // eslint-disable-next-line no-undef
        this.instance = UE.getEditor(this.randomId)
        this.instance.addListener('ready', () => {
          this.ready = true
          this.$emit('ready', this.instance)
        })
      })
    },
    getUEContent () {
      return this.instance.getContent()
    },
    setText (con) {
      // eslint-disable-next-line no-undef
      this.instance = UE.getEditor(this.randomId)
      this.instance.setContent(con)
    }
  }
}
</script>

在这里插入图片描述
5. App.vue中使用

<template>
  <div id="app">
    <Ueditor v-model="title" @ready="editorReady" />
  </div>
</template>

<script>
import Ueditor from '@/components/Ueditor'

export default {
  name: 'App',
  components: {
    Ueditor
  },
  data() {
    return {
      title: 'init'
    };
  },
  created() {
    // console.log('111111111');
  },
  methods: {
    editorReady (instance) {
      instance.setContent(this.title)
    }, 
  },
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

大佬GitHub

https://github.com/sanluan/PublicCMS

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
插件详细说明地址https://blog.csdn.net/viqecel/article/details/79670613 =========================================== 一,后台网设置. 选择ueditor 二,修改member\editor\ueditor\ueditor.config.js 366行 的 a: ['target', 'href', 'title', 'class', 'style'], 修改为 a: ['target', 'href', 'title', 'class', 'style', 'name'], 403行的 img: ['src', 'alt', 'title', 'width', 'height', 'id', '_src', 'loadingclass', 'class', 'data-latex'], 修改为 img: ['src', 'alt', 'title', 'width', 'height', 'id', '_src', 'loadingclass', 'class', 'data-latex','anchorname','word_img','style'], 三,修改member\editor\ueditor\init.inc.php 注释掉25行 即 $editor .= 'serverUrl:UPPath+"?from=editor&moduleid;='.$moduleid.'",'; 然后.查找 'fullscreen', 批量替换为 'fullscreen', 'wordimage' 其实就是在后面增加 转存按钮 四,把百度编辑器ueditor目录中的php文件复制到系统对应目录中 即保证 member\editor\ueditor\php\controller.php 这个 控制器文件可访问 然后修改controller.php 文件 第4行 把Chongqing首字母设置为大写] 即 date_default_timezone_set("Asia/Chongqing"); 五,修改图片上传保存目录.即php/config.json 即 11行 替换为绝对路径,你的首页网地址直接填这即可,后面不加斜线,这里如果不加绝对路径.则没法自动读取第一个图片为标题图片. "imageUrlPrefix": "这里修改为你的网首页网址不加后斜线", 12行替换为下面一行. 即修改图片保存路径,与原系统一致即可 "imagePathFormat": "/file/upload/{yyyy}{mm}/{dd}/{time}{rand:2}", /* 上传保存路径,可以自定义保存路径和文件名格式 */ 后台系统维护,点击更新所有缓存,ctrl+f5强制刷新后台
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值