vue问题四:富文本编辑器上传图片
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问题四:富文本编辑器上传图片的更多相关文章
- 富文本编辑器上传图片需要配置js,后台代码
富文本编辑器上传图片需要配置js,后台代码
- Vue基于vue-quill-editor富文本编辑器使用心得
vue-quill-editor的guthub地址,现在市面上有很多的富文本编辑器,我个人还是非常推荐Vue自己家的vue-quill-deitor,虽然说只支持IE10+,但这种问题,帅给别人吧! ...
- vue集成百度富文本编辑器
1.前期工作,访问百度富文本官网下载相应的百度富文本文件,根据后端用的技术下载相应的版本,建议下载最新版UTF-8版 (有图有真相,看图) https://ueditor.baidu.com/webs ...
- Vue集成tinymce富文本编辑器并实现本地化指南(2019.11.21最新)
tinymce是一款综合口碑特别好.功能异常强大的富文本编辑器,在某些网站,甚至享有"宇宙最强富文本编辑器"的称号.那么,在Vue项目中如何集成呢?这并不困难,只需要参照官方教程 ...
- ueditor富文本编辑器——上传图片按钮卡顿,响应慢
最近负责将公司官网从静态网站改版成动态网站,方便公司推广营销人员修改增加文案,避免官网文案维护过于依赖技术人员.在做后台管理系统时用到了富文本编辑器Ueditor,因为公司有一个阿里云文件资源服务器, ...
- Ueditor富文本编辑器--上传图片自定义上传操作
最近负责将公司官网从静态网站改版成动态网站,方便公司推广营销人员修改增加文案,避免官网文案维护过于依赖技术人员.在做后台管理系统时用到了富文本编辑器Ueditor,因为公司有一个阿里云文件资源服务器, ...
- Vue整合Quill富文本编辑器
Quill介绍 Quill是一款开源的富文本编辑器,基于可扩展的架构设计,提供丰富的 API 进行定制.截止2021年1月,在github上面已有28.8k的star. Quill项目地址:https ...
- vue 集成百度富文本编辑器
<template> <div> <textarea style="display:none" id="editor_content&quo ...
- 使用UMeditor富文本编辑器上传图片
注:本文系作者原创,但可随意转载. 最近写自己的网站玩儿,写到博客的部分,打算使用UMeditor,因为之前也用过(但是好像没实现图片上传的功能),感觉用起来还比较简单. 不过还是折腾了一下午...遇 ...
随机推荐
- ORA-00001:unique constraint (use.sys_c0013338) violated
从报错的 信息来看,是唯一约束.但是第一眼看到use.sys_c0013338 误以为是张表,(老司机帆船了啊,水还是咸的!) 解决方法: SQL>select table_name from ...
- python多线程之_thread
多线程类似于同时执行多个不同程序,多线程运行有如下优点: 使用线程可以把占据长时间的程序中的任务放到后台去处理. 用户界面可以更加吸引人,这样比如用户点击了一个按钮去触发某些事件的处理,可以弹出一个进 ...
- dispatch事件分发
//赋值,监听change事件var el = document.getElementById('selectTimeHide');el.value=rs.text;//赋值el.dispatchEv ...
- zencart通过产品id 批量添加推荐产品
1.修改 admin/featured.php 查找 pre_add_confirmation 将 pre_add_confirmation 与 break; 之间的代码,用下面的代码替换即可 &l ...
- Idea发布项目到Docker
一.Docker开启远程访问 [root@local host ~]# vi /lib/systemd/system/docker.service #修改ExecStart这行 ExecStart=/ ...
- HDU - 6386 Age of Moyu (双端队列+bfs)
题目链接 双端队列跑边,颜色相同的边之间的花费为0,放进队首:不同的花费为1,放进队尾. 用Dijkstra+常数优化也能过 #include<bits/stdc++.h> using n ...
- python之爬取网页数据总结(一)
今天尝试使用python,爬取网页数据.因为python是新安装好的,所以要正常运行爬取数据的代码需要提前安装插件.分别为requests Beautifulsoup4 lxml 三个插件 ...
- 在神经网络中weight decay
weight decay(权值衰减)的最终目的是防止过拟合.在损失函数中,weight decay是放在正则项(regularization)前面的一个系数,正则项一般指示模型的复杂度,所以weigh ...
- 【leetcode】Trips and Users
The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are b ...
- Unknown or unsupported command 'install'
由于电脑中存在多个python,导致pip install numpy出现标题这样的错误 结局方案; 在想要的python文件夹中的Scripts,shift右键点开命令行,pip.exe insta ...