vue-quill-editor + element-ui upload实现富文本图片上传
代码贴上
<template>
<div class="quill-editor-example">
<div class="box">
<el-upload class="upload-demo" name="editorUpload" accept="image/*" action="/api/upload/singleFile" :show-file-list="false" :on-success="success">
</el-upload>
</div>
<quill-editor v-model="content" ref="myQuillEditor" class="editer" :options="editorOption" @ready="onEditorReady($event)">
</quill-editor>
<button @click="submit">提交</button>
</div>
</template>
<script>
import { quillEditor } from 'vue-quill-editor';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
// 工具栏配置
const toolbarOptions = [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }],
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }],
[{ 'indent': '-1' }, { 'indent': '+1' }],
[{ 'direction': 'rtl' }],
[{ 'size': ['small', false, 'large', 'huge'] }],
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }],
[{ 'font': [] }],
[{ 'align': [] }],
['link', 'image'],
['clean']
];
export default {
data() {
let _this = this;
return {
name: '02-example',
content: "<p style='color:red;'>example content</p>",
editorOption: {
modules: {
toolbar: {
container: toolbarOptions, // 工具栏
handlers: {
'image': function(value) {
if (value) {
document.querySelector(".box input[name='editorUpload']").click();
} else {
this.quill.format('image', false);
}
}
}
}
}
}
}
},
components: {
quillEditor
},
computed: {
editor() {
return this.$refs.myQuillEditor.quill
}
},
mounted() {
console.log('this is my editor, example 2', this.editor)
},
methods: {
onEditorReady(editor) {
console.log('editor ready!', editor)
},
submit() {
console.log(this.content);
this.$message.success('提交成功!');
},
success(res, file, fileList) {
// res为图片服务器返回的数据
// 获取富文本组件实例
let quill = this.$refs.myQuillEditor.quill
// 如果上传成功
// if (res.code === '200' && res.info !== null) {
// 获取光标所在位置
let length = quill.getSelection().index;
// 插入图片 res.info为服务器返回的图片地址
quill.insertEmbed(length, 'image', res.msg)
// 调整光标到最后
quill.setSelection(length + 1)
// } else {
// this.$message.error('图片插入失败')
// }
console.log(res)
}
},
} </script>
vue-quill-editor + element-ui upload实现富文本图片上传的更多相关文章
- summernote富文本图片上传,增加视频上传功能、批量上传方法
Summernote 是一个简单灵活的所见即所得的 HTML 在线编辑器,基于 jQuery 和 Bootstrap 构建,支持快捷键操作,提供大量可定制的选项. 但是却只有图片上传功能,没有视频上传 ...
- layui 富文本 图片上传 后端PHP接口
<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/ ...
- 基于element ui 实现七牛云自定义key上传文件,并监听更新上传进度
借助上传Upload 上传组件的 http-request 覆盖默认的上传行为,可以自定义上传的实现 <el-upload multiple ref="sliderUpload&quo ...
- 关于editor网页编辑器ueditor.config.js 配置图片上传
最近公司项目在做一个门户网站,其中新闻和简介等部分使用到了ueditor编辑器,但是上级明确指示需要图片上传这个功能,这时却发现图片上传功能不能正常使用,上传时一直报错,网上收了好几个处理办法,都说的 ...
- AntDesign vue学习笔记(七)Form 读写与图片上传
AntDesign Form使用布局相比传统Jquery有点繁琐 (一)先读写一个简单的input为例 <a-form :form="form" layout="v ...
- 【Django组件】KindEditor富文本编辑器上传文件,html样式文本,VUE异步提交数据(易懂版)
1:下载与配置 适合版本: python3 下载:http://kindeditor.net/down.php 文档:http://kindeditor.net/doc.php 将文件包放入stati ...
- 使用element UI el-upload组件实现视频文件上传及上传进度显示方法总结
实现效果: 上传中: 上传完成: 代码: <el-form-item label="视频上传" prop="Video"> <!-- acti ...
- vue富文本编辑器vue-quill-editor使用总结(包含图片上传,拖拽,放大和缩小)
vue-quill-editor是vue很好的富文本编辑器,富文本的功能基本上都支持,样式是黑白色,简洁大方. 第一步下载 vue-quill-editor: npm i vue-quill-edit ...
- vue项目富文本编辑器vue-quill-editor之自定义图片上传
使用富文本编辑器的第一步肯定是先安装依赖 npm i vue-quill-editor 1.如果按照官网富文本编辑器中的图片上传是将图片转为base64格式的,如果需要上传图片到自己的服务器,需要修改 ...
随机推荐
- Spark技术内幕:Master基于ZooKeeper的High Availability(HA)源代码实现
假设Spark的部署方式选择Standalone,一个採用Master/Slaves的典型架构,那么Master是有SPOF(单点故障,Single Point of Failure).Spark能够 ...
- .net的程序的逆向分析。
背景:碰到一个由c#写的exe,由于之前没有分析过.net的程序,记录下分析流程. 1)peid加载判断类型,可以看出没有加壳. 2)搜索c#的反编译以及调试工具. 1.NET.Reflector以及 ...
- oracle基本建表语句
oracle基本建表语句 2010-09-20 10:37:33| 分类: 数据库 | 标签:数据库 oracle |字号 订阅 --创建用户create user han identifie ...
- Bing必应地图中国API入门讲座之八:显示驾车路线
Bing必应地图中国API入门讲座之八:显示驾车路线 2011-05-24 14:47:36| 分类: Bing&Google|字号 订阅 这篇文章非常值得纪念,因为我是在Googl ...
- 【Codevs 1376】帕秋莉•诺蕾姬
http://codevs.cn/problem/1376/ 枚举修改哪两位,将sum减去之前位置的数+交换之后 %m==0即可 预处理26的次方+O(n^2) // <1376.cpp> ...
- Apache Ignite——集合分布式缓存、计算、存储的分布式框架
Apache Ignite内存数据组织平台是一个高性能.集成化.混合式的企业级分布式架构解决方案,核心价值在于可以帮助我们实现分布式架构透明化,开发人员根本不知道分布式技术的存在,可以使分布式缓存.计 ...
- Hadoop安装配置(ubuntu-12.04.2-server-amd64)
环境如下: ubuntu-12.04.2-server-amd64 hadoop-1.0.4 VirtualBox 1.在VBox中安装Ubuntu Server,用户名和密码都是hadoop,安装完 ...
- Could not find modernizr-2.6.2 in any of the sources
- 3-1 vue生存指南 - todolist实现-数据渲染
由于Vue.js作者是中国人,会说汉语,所以国内生态会更好一点.Vue.js作者是尤雨溪,
- MySQL5.6 windows msi安装介绍
200 ? "200px" : this.width)!important;} --> 一.功能介绍 1.MySQL Servers 该功能是mysql主要的服务,也是必须安 ...