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. TensorFlow入门——MNIST深入

    #load MNIST data import tensorflow.examples.tutorials.mnist.input_data as input_data mnist = input_d ...

  2. Spring Boot整合actuator实现监控管理

    Spring Boot使用actuator监控管理 1.在pom文件中导入相关的依赖 <dependency> <groupId>org.springframework.boo ...

  3. ffmpeg3.3.2命令行参数笔记

    组成: 1.libavformat:用于各种音视频封装格式的生成和解析,包括获取解码所需信息以生成解码上下文结构和读取音视频帧等功能,包含demuxers和muxer库: 2.libavcodec:用 ...

  4. Tensorflow模型移植Arm之一:C与Python互相调用

    一.C调用Python 1.新建一个Python文件,名称为py_multipy.py: #import numpy as np def multiply(a=1,b=2): print('Funct ...

  5. typedef 返回类型(*Function)(参数表) ——typedef函数指针

    //首先看一下函数指针怎么用 #include <iostream> using namespace std; //定义一个函数指针pFUN,它指向一个返回类型为char,有一个整型的参数 ...

  6. php禁止个别ip访问网站

    PHP禁止个别IP访问自己的网站,可以看看下面的方法. function get_ip_data(){ $ip=file_get_contents("http://ip.taobao.com ...

  7. usb四种传输模式bulk

    当USB插入USB总线时,USB控制器会自动为该USB设备分配一个数字来标示这个设备.另外,在设备的每个端点都有一个数字来表明这个端点.USB设备驱动向USB控制器驱动请求的每次传输被称为一个事务(T ...

  8. Java介绍、环境的搭建及结构化程序

    一.Java 简介及环境配置: JDK和JRE的区别:JRE(Java Runtime Environment)Java运行时环境有些程序运行需要Java环境,因此JRE只是给客户端使用的. JDK( ...

  9. Kendo UI for jQuery使用教程:操作系统/jQuery支持等

    [Kendo UI for jQuery最新试用版下载] Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support ...

  10. 使用sql做迁移矩阵

    在数据分析数据差异的时候 经常用到一个图叫做迁移矩阵. 其中里面的值可以是数量也可以是百分比,我们可以从一个时间点明确的看到在另一个时间点或者另一个时间点 子类之间数量迁移. 比如这次我在公司与业务核 ...