怎么在vue项目中使用ueditor自定义一个上传按钮功能

发布时间:2021-03-11 16:23:41 作者:Leah
来源:亿速云 阅读:600

这篇文章将为大家详细讲解有关怎么在vue项目中使用ueditor自定义一个上传按钮功能,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

首先是给ueditor添加自定义按钮:

1,打开ueditor.all.js,找到btnCmds,大概在27854行,如下图,在数组添加一个自定义的按钮名称,我写的是"love"

怎么在vue项目中使用ueditor自定义一个上传按钮功能

ueditor.all.js

2,给按钮添加事件

还是在ueditor.all.js文件内找到commands指令 给刚才定义的按钮扩展事件,如下:

怎么在vue项目中使用ueditor自定义一个上传按钮功能

给按钮添加事件

我这里绑定的事件在vue里面已经定义好了 这里用$emit 绑定上去,然后在页面里面监听。bus是自定义的vue实例,因为整个项目是结合vue在使用。

3.给按钮添加图标icon

打开themes/default/css/ueditor.css.在文件下面添加即可,如下:

.edui-default .edui-toolbar .edui-for-love .edui-icon {
  background: url(../images/video.png) no-repeat 50% 50%;
}

这里的.edui-for-love后面的love就是刚才定义按钮的名称,由于我所有按钮都重写样式了,所以全部采用覆盖了;

怎么在vue项目中使用ueditor自定义一个上传按钮功能

给按钮添加图标

4. 页面监听点击事件

这里的内容就是vue的基础了,可以自己看文档,简单如下

怎么在vue项目中使用ueditor自定义一个上传按钮功能

先给页面定义一个元素添加绑定事件

怎么在vue项目中使用ueditor自定义一个上传按钮功能

然后监听ueditor传递过来的点击事件showUpload

怎么在vue项目中使用ueditor自定义一个上传按钮功能

在methods里面定义showUpload事件(这里命名重复了 无所谓)

这样 ,自定义上传按钮已经完成了。

下面给大家介绍vue项目中使用ueditor的例子

以vue-cli生成的项目为例

1.static文件夹下先放入ueditor文件

2.index.html添加如下代码

<script type="text/javascript" charset="utf-8" src="static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="static/ueditor/ueditor.all.min.js"></script>

3.webpack.base.conf.js添加如下配置

externals: {
  'UE': 'UE',
 },

4.index.html中添加

<script type="text/javascript">
 window.UEDITOR_HOME_URL = "/static/ueditor/";//配置路径设定为UEditor所放的位置
</script>

5.editor组件

<template>
 <div>
  <mt-button @click="geteditor()" type="danger">获取</mt-button>
  <script id="editor" type="text/plain" ></script>
 </div>
</template>
<script>
const UE = require('UE');// eslint-disable-line
export default {
 name: 'editorView',
 data: () => (
  {
   editor: null,
  }
 ),
 methods: {
  geteditor() {
   console.log(this.editor.getContent());
  },
 },
 mounted() {
  this.editor = UE.getEditor('editor');
 },
 destroyed() {
  this.editor.destroy();
 },
};
</script>
<style>
</style>

关于怎么在vue项目中使用ueditor自定义一个上传按钮功能就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. vue项目中使用ueditor的方法
  2. 怎么在vue项目中实现一个图片上传功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue ueditor

上一篇:如何在Tensorflow中使用Tensorboard实现可视化

下一篇:怎么用git迁移Laravel项目至新开发环境

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》