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. el-table + el-form实现可编辑表格字段验证

    表格输入信息很常见,因此表格的验证也很必要,el-form提供了输入框验证.可以和表格结合起来用,使用效果     HTML: <div class="table_box"& ...

  2. dedecms 缩略图路径修改

  3. linux命令详解——sort

    [原文链接]:http://www.cnblogs.com/51linux/archive/2012/05/23/2515299.html 1 sort的工作原理 sort将文件的每一行作为一个单位, ...

  4. Delphi 参数的传递

  5. Single List Reversion

    LeetCode 1. 基于头插法的迭代: public ListNode reverseList(ListNode head) { if(head == null) return null; Lis ...

  6. C++的一些黑暗料理

    本文中的“黑暗料理”仅限本人在学习C++的过程中感觉易忘.有趣.不为大多数人所知的一些特性. 1. C++中int型数据在VC++环境下最小值为什么是 -32678,而不是-32677,其中涉及到原码 ...

  7. ImportError: attempted relative import with no known parent package

    或者检查所导包是否存在__init__.py文件,没有则添加上即可使当前文件夹变为包.

  8. 【每日一包0003】kind-of

    github地址:https://github.com/ABCDdouyae... kind-of 判断数据类型用法:kind-of(date)返回:string 数据类型 January undef ...

  9. JavaScript 数组1—索引数组

    索引数组:下标是数字数组 ㈠什么是? 内存中连续储存多个数据的数据结构,再起一个统一的名字 ㈡为什么? ①普通的变量只能存储一个数据程序=数据结构+算法 ②算法:解决问题的步骤 ③数据结构:数据在内存 ...

  10. CSS3 3D转换——rotateX(),rotateY(),rotateZ()

    CSS3 允许使用 3D 转换来对元素进行格式化. ㈠浏览器支持 Internet Explorer 10 和 Firefox 支持 3D 转换. Chrome 和 Safari 需要前缀 -webk ...