vue使用富文本编辑器上传图片:

我是用的是wangEditor 富文本编辑器 demo:http://www.wangeditor.com/
1).安装依赖:npm install wangeditor
2).我自己是创建了一个组件这样再用到的时候可以直接调用(可能有更简单的方法)
<template lang="html">

  <div class="editor">
<div ref="toolbar" class="toolbar">
</div>
<div ref="editor" class="text">
</div>
</div>
</template> <script>
import E from 'wangeditor'
let editor=null
export default {
name: 'Editorbar',
data () {
return {
info_: null
}
},
model: {
prop: 'value',
event: 'change'
},
props: {
value: {
type: String,
default: ''
},
isClear: {
type: Boolean,
default: false
}
},
watch: {
isClear (val) {
// 触发清除文本域内容
if (val) {
editor.txt.clear()
this.info_ = null
}
},
value (val) {
// 使用 v-model 时,设置初始值
editor.txt.html(val)
}
},
mounted () {
this.seteditor()
},
methods: {
seteditor () {
editor = new E(this.$refs.toolbar, this.$refs.editor)
editor.customConfig.uploadImgShowBase64 = true // base 64 存储图片
editor.customConfig.uploadImgServer = 'http://47.106.198.122/api/CanteenAdmin/CanteenManagement/UploadImage'// 配置服务器端地址
editor.customConfig.uploadImgHeaders = { 'token':sessionStorage.getItem('token') }// 自定义 header
editor.customConfig.uploadFileName = 'image' // 后端接受上传文件的参数名
editor.customConfig.uploadImgMaxSize = 2 * 1024 * 1024 // 将图片大小限制为 2M
editor.customConfig.uploadImgMaxLength = 6 // 限制一次最多上传 3 张图片
editor.customConfig.uploadImgTimeout = 3 * 60 * 1000 // 设置超时时间
// this.editor.customConfig.uploadParams = {formFile:'2'};
// 配置菜单
editor.customConfig.menus = [
'bold', // 粗体
'underline', // 下划线
'link', // 插入链接
'quote', // 引用
'emoticon', // 表情
'image', // 插入图片
'table', // 表格
'code', // 插入代码 ] editor.customConfig.uploadImgHooks = {
fail: (xhr, editor, result) => {
// 插入图片失败回调
},
success: (xhr, editor, result) => {
// 图片上传成功回调
//
// let imgUrl = result.data;
// insertImg(imgUrl)
},
timeout: (xhr, editor) => {
// 网络超时的回调
},
error: (xhr, editor) => {
console.log(editor)
// 图片上传错误的回调
},
customInsert: (insertImg, result, editor) => {
// 图片上传成功,插入图片的回调
console.log(result);
// if(result.code == 200){
var url = result.data;
insertImg(url)//将内容插入到富文本中
// console.log(insertImg(url)+"DFDF")
// console.log(data+"dsfd")
// }
}
}; editor.customConfig.onchange = (html) => {
this.info_ = html // 绑定当前逐渐地值
this.$emit('change', this.info_) // 将内容同步到父组件中
console.log(this.info_ )
}; // 创建富文本编辑器
editor.create()
}
}
}
</script> <style lang="css">
.editor {
width: 80%;
margin-left: 4%;
}
.toolbar { border: 1px solid #ccc;
}
.w-e-menu{
z-index:1 !important;
}
.text {
width:100%;
border: 1px solid #ccc;
height: 300px;
}
</style>

editor.vue

<!--富文本编辑器-->
<div style="margin-top:2%;margin-left: 1%">
<editor-bar v-model="zldata.info" :isClear="isClear"></editor-bar>
</div> js:
<script>
import EditorBar from './editor'
export default {
data: function () {
return {
isClear: false,
zldata: {
info:'',
},
}
},
components: {
EditorBar
}, } </script>

调用

喜欢的给个赞吧!!!

vue问题四:富文本编辑器上传图片的更多相关文章

  1. 富文本编辑器上传图片需要配置js,后台代码

    富文本编辑器上传图片需要配置js,后台代码

  2. Vue基于vue-quill-editor富文本编辑器使用心得

    vue-quill-editor的guthub地址,现在市面上有很多的富文本编辑器,我个人还是非常推荐Vue自己家的vue-quill-deitor,虽然说只支持IE10+,但这种问题,帅给别人吧! ...

  3. vue集成百度富文本编辑器

    1.前期工作,访问百度富文本官网下载相应的百度富文本文件,根据后端用的技术下载相应的版本,建议下载最新版UTF-8版 (有图有真相,看图) https://ueditor.baidu.com/webs ...

  4. Vue集成tinymce富文本编辑器并实现本地化指南(2019.11.21最新)

     tinymce是一款综合口碑特别好.功能异常强大的富文本编辑器,在某些网站,甚至享有"宇宙最强富文本编辑器"的称号.那么,在Vue项目中如何集成呢?这并不困难,只需要参照官方教程 ...

  5. ueditor富文本编辑器——上传图片按钮卡顿,响应慢

    最近负责将公司官网从静态网站改版成动态网站,方便公司推广营销人员修改增加文案,避免官网文案维护过于依赖技术人员.在做后台管理系统时用到了富文本编辑器Ueditor,因为公司有一个阿里云文件资源服务器, ...

  6. Ueditor富文本编辑器--上传图片自定义上传操作

    最近负责将公司官网从静态网站改版成动态网站,方便公司推广营销人员修改增加文案,避免官网文案维护过于依赖技术人员.在做后台管理系统时用到了富文本编辑器Ueditor,因为公司有一个阿里云文件资源服务器, ...

  7. Vue整合Quill富文本编辑器

    Quill介绍 Quill是一款开源的富文本编辑器,基于可扩展的架构设计,提供丰富的 API 进行定制.截止2021年1月,在github上面已有28.8k的star. Quill项目地址:https ...

  8. vue 集成百度富文本编辑器

    <template> <div> <textarea style="display:none" id="editor_content&quo ...

  9. 使用UMeditor富文本编辑器上传图片

    注:本文系作者原创,但可随意转载. 最近写自己的网站玩儿,写到博客的部分,打算使用UMeditor,因为之前也用过(但是好像没实现图片上传的功能),感觉用起来还比较简单. 不过还是折腾了一下午...遇 ...

随机推荐

  1. 数据库命令行工具USQL、mycli、litecli、pgcli

    USQL USQL 是一款使用 Go 语言开发的支持 SQL/NoSQL 数据库的通用命令行工具,它支持多种主流的数据库软件,目前最新版本是usql 0.7.0.比如 PostgreSQL.MySQL ...

  2. OpenSSL(1)密钥和证书管理

    OpenSSL是一个开源项目,包括密码库和SSL/TLS工具集. 从项目的官方站点可以看到: OpenSSL项目是安全套接字层( secure sockets layer, SSL)和传输层安全( t ...

  3. idea一键生成mybatis工具

    1.创建maven项目,导包 <build> <plugins> <plugin> <groupId>org.mybatis.generator< ...

  4. CentOS 7.x and RHEL 7.x Install qemu-kvm

    ref: https://www.linuxtechi.com/install-kvm-hypervisor-on-centos-7-and-rhel-7/        https://www.th ...

  5. windows文本操作字符命令含义

    r 打开只读文件,该文件必须存在. r+ 打开可读写的文件,该文件必须存在. rb+ 读写打开一个二进制文件,只允许读写数据. rt+ 读写打开一个文本文件,允许读和写. w 打开只写文件,若文件存在 ...

  6. 009(1)-saltstack之salt-ssh的使用及配置管理LAMP状态的实现

    1 salt-ssh的使用 1. 安装salt-ssh[root@slave1 .ssh]# yum install -y salt-ssh 2. 配置salt-ssh # Sample salt-s ...

  7. Dubbo 04 服务化最佳实现流程

    Dubbo 04 服务化最佳实践 分包 建议将服务接口.服务模型.服务异常等均放在 API 包中,因为服务模型和异常也是 API 的一部分,这样做也符合分包原则:重用发布等价原则(REP),共同重用原 ...

  8. PAT Basic 1014 福尔摩斯的约会 (20 分)

    大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm.大侦探很快就明白了,字条上奇 ...

  9. Fatal Error: Out of memory php内存溢出处理三种方法

    有时候我们在运行php程序的时候会发现 Fatal Error: Out of memory 这样的提示,这有可能是程序中用到了大量了变量和对象,导致分配的内存不够用. 修改php.ini文件里的me ...

  10. 清除zencart分类页多页后面的&disp_order &sort字符串的方法

    在includes\classes\split_page_results.php页面中的function display_links()函数第一行添加如下两行代码即可$parameters=preg_ ...