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,因为之前也用过(但是好像没实现图片上传的功能),感觉用起来还比较简单. 不过还是折腾了一下午...遇 ...
随机推荐
- Linux下部署Kafka分布式集群,安装与测试
注意:部署Kafka之前先部署环境JAVA.Zookeeper 准备三台CentOS_6.5_x64服务器,分别是:IP: 192.168.0.249 dbTest249 Kafka IP: 192. ...
- 13、Nginx七层负载均衡
1.Nginx负载均衡基本概述 1.1为什么需要使用负载均衡 当我们的Web服务器直接面向用户,往往要承载大量并发请求,单台服务器难以负荷,我使用多台WEB服务器组成集群,前端使用Nginx负载均衡, ...
- Android单元测试之google官例CalculatorTest
执行测试用例类CalculatorTest 设置genymotion可见: Android Studio界面中,依次单击菜单项 View >Toolbar.即可见改工具按钮. 启动gen ...
- Ubuntu 部署Python开发环境
一.开发环境包安装 sudo apt-get install git-core sudo apt-get install libxml2-dev sudo apt-get install libxsl ...
- A Neural Probabilistic Language Model (2003)论文要点
论文链接:http://www.jmlr.org/papers/volume3/bengio03a/bengio03a.pdf 解决n-gram语言模型(比如tri-gram以上)的组合爆炸问题,引入 ...
- postgresql 锁表查询语句
1 查找锁表的pid select pid from pg_locks l join pg_class t on l.relation = t.oid where t.relkind = 'r' an ...
- QR分解迭代求特征值——原生python实现(不使用numpy)
QR分解: 有很多方法可以进行QR迭代,本文使用的是Schmidt正交化方法 具体证明请参考链接 https://wenku.baidu.com/view/c2e34678168884868762d6 ...
- Linux查看端口的连接数
一.查看哪些IP连接本机 netstat -an 二.查看TCP连接数 1)统计80端口连接数 netstat -nat | grep -i "80" | wc -l 2)统计ht ...
- VCL界面开发必备装备!DevExpress VCL v19.1.5你值得拥有
DevExpress VCL Controls是 Devexpress公司旗下最老牌的用户界面套包.所包含的控件有:数据录入,图表,数据分析,导航,布局,网格,日程管理,样式,打印和工作流等,让您快速 ...
- Linux 开启相关端口及查看已开启端口
防火墙层面: /sbin/iptables -I INPUT -p tcp --dport 8011 -j ACCEPT #开启8011端口 /etc/rc.d/init.d/iptables ...