vue富文本vue-quill-editor
这个富文本需要装一下插件
"quill": "^1.3.6"
"quill-image-drop-module": "^1.0.3", //压缩图片
"quill-image-resize-module": "^3.0.0", //图片大小控制
"vue-quill-editor": "^3.0.6",
使用
webpack中加一下配置
plugins: [
new webpack.ProvidePlugin({
'window.Quill': 'quill/dist/quill.js',
'Quill': 'quill/dist/quill.js'
})
],
main.js注册组件
// 编辑器
import VueQuillEditor from 'vue-quill-editor' import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css' Vue.use(VueQuillEditor)
页面使用
<template>
<quill-editor
v-model="content"
:content="content"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@ready="onEditorReady($event)">
</quill-editor>
</template> <script>
import { Quill } from 'vue-quill-editor'
import { ImageDrop } from 'quill-image-drop-module'
import ImageResize from 'quill-image-resize-module'
Quill.register('modules/imageDrop', ImageDrop)
Quill.register('modules/imageResize', ImageResize) export default {
data () {
return {
name: 'register-modules-example',
content: `1231`,
editorOption: {
modules: {
history: {
delay: 1000,
maxStack: 50,
userOnly: false
},
toolbar: [
['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] }],
[{ 'font': [] }],
[{ 'color': [] }, { 'background': [] }],
[{ 'align': [] }],
['clean'],
['link', 'image', 'video']
],
imageDrop: true,
imageResize: {
displayStyles: {
backgroundColor: 'black',
border: 'none',
color: 'white'
},
modules: [ 'Resize', 'DisplaySize', 'Toolbar' ]
}
}
}
}
},
methods: {
onEditorBlur (editor) {
// console.log('editor blur!', editor)
console.log(editor)
},
onEditorFocus (editor) {
// console.log('editor focus!', editor)
},
onEditorReady (editor) {
// console.log('editor ready!', editor)
}
}
}
</script>
自定义图片上传 参考处
toolbar: {
container: toolbarOptions,
handlers: {
'image': function (value) {
if (value) {
// 调用element UI图片上传
document.querySelector('#uploadImg .el-upload').click()
} else {
this.quill.format('image', false)
}
}
}
},
handers处重写 图片的点击事件
触发 element 的 upload的点击事件
upload上传成功的回调事件
// 图片上传成功方法
handleSuccess (response, file, fileList) {
// 获取富文本组件实例
let quill = this.$refs.QuillEditor.quill
// 如果上传成功
if (response) {
// 获取光标所在位置
let length = quill.getSelection().index
// 插入图片,第三个参数为服务器返回的图片链接地址
quill.insertEmbed(length, 'image', response.data.url)
// 调整光标到最后
quill.setSelection(length + 1)
} else {
// 提示信息,需引入Message
alert('图片插入失败')
}
}
代码
<template>
<div class="quill-editor">
<el-upload
class="upload-demo"
action="http://mock/2/api/richUpload"
accept=".jpg,.jpeg,.png,.gif]"
:headers="headers"
:show-file-list="false"
:on-success="handleSuccess"
:before-upload="beforeUpload"
id="uploadImg"
ref="uploadImg"
>
上传
</el-upload>
<quill-editor
v-model="content"
:content="content"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@ready="onEditorReady($event)"
ref="QuillEditor">
</quill-editor>
</div>
</template> <script>
import { Quill } from 'vue-quill-editor'
import { ImageDrop } from 'quill-image-drop-module'
import ImageResize from 'quill-image-resize-module'
Quill.register('modules/imageDrop', ImageDrop)
Quill.register('modules/imageResize', ImageResize) 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] }],
[{ 'font': [] }],
[{ 'color': [] }, { 'background': [] }],
[{ 'align': [] }],
// ['clean'],
['link', 'image', 'video']
]
export default {
data () {
return {
name: 'register-modules-example',
content: `1231`,
editorOption: {
modules: {
history: {
delay: 1000,
maxStack: 50,
userOnly: false
},
toolbar: {
container: toolbarOptions,
handlers: {
'image': function (value) {
if (value) {
// 调用iview图片上传
console.log(document.querySelector('#uploadImg .el-upload'))
document.querySelector('#uploadImg .el-upload').click()
console.log(value, 1231)
} else {
console.log(212222222222222)
this.quill.format('image', false)
}
}
}
},
imageDrop: true,
imageResize: {
displayStyles: {
backgroundColor: 'black',
border: 'none',
color: 'white'
},
modules: [ 'Resize', 'DisplaySize', 'Toolbar' ]
}
}
},
headers: {
'Authorization': 'Bearer ' + sessionStorage.getItem('token')
}
}
},
methods: {
onEditorBlur (editor) {
// console.log('editor blur!', editor)
console.log(editor)
},
onEditorFocus (editor) {
// console.log('editor focus!', editor)
},
onEditorReady (editor) {
// console.log('editor ready!', editor)
},
// 上传之前加认证信息
beforeUpload () {
this.headers.Authorization = 'Bearer ' + sessionStorage.getItem('token')
},
// 图片上传成功方法
handleSuccess (response, file, fileList) {
// 获取富文本组件实例
let quill = this.$refs.QuillEditor.quill
// 如果上传成功
if (response) {
// 获取光标所在位置
let length = quill.getSelection().index
// 插入图片,res为服务器返回的图片链接地址
quill.insertEmbed(length, 'image', response.data.url)
// 调整光标到最后
quill.setSelection(length + 1)
} else {
// 提示信息,需引入Message
// Message.error('图片插入失败')
alert('图片插入失败')
}
}
}
}
</script>
tip: 在显示的时候会出现样式丢失的问题,需要加一个 class = "ql-editor"
<div class=" ql-editor" v-html="item.content"></div>
vue富文本vue-quill-editor的更多相关文章
- vue 富文本编辑器 项目实战用法
1.挑个富文本编辑器 首先针对自己项目的类型,确定自己要用啥编辑器. 1.1 wangeditor 如果一般类似博客这种项目不需要花里胡哨的,功能也不要求贼多的,推荐一下wangeditor(点击跳转 ...
- vue+富文本编辑器UEditor
vue+富文本编辑器UEditor 昨天的需求是把textarea换成富文本编辑器的形式, 网上找了几种富文本编辑器ueditor.tinymce等, 觉得ueditor实现双向绑定还挺有意思, 分享 ...
- 富文本编辑器...quill 的使用放...
移动端 quill 时候用的 是 div 而不是 textarea.... 引入 dom <link href="//cdn.quilljs.com/1.3.6/quill.snow. ...
- 现代富文本编辑器Quill的内容渲染机制
DevUI是一支兼具设计视角和工程视角的团队,服务于华为云DevCloud平台和华为内部数个中后台系统,服务于设计师和前端工程师.官方网站:devui.designNg组件库:ng-devui(欢迎S ...
- vue富文本编辑器vue-quill-editor使用总结(包含图片上传,拖拽,放大和缩小)
vue-quill-editor是vue很好的富文本编辑器,富文本的功能基本上都支持,样式是黑白色,简洁大方. 第一步下载 vue-quill-editor: npm i vue-quill-edit ...
- Vue富文本编辑器(图片拖拽缩放)
富文本编辑器(图片拖拽缩放) 需求: 根据业务要求,需要能够上传图片,且上传的图片能在移动端中占满屏幕宽度,故需要能等比缩放上传的图片,还需要能拖拽.缩放.改变图片大小.尝试多个第三方富文本编辑器,很 ...
- 富文本编辑器Quill(一)简单介绍
Quill是一个很流行的富文本编辑器,github上star大约21k: github:https://github.com/quilljs/quill/ 官网: https://quilljs.co ...
- 富文本编辑器Quill(二)上传图片与视频
image与video在Quill formats中属于Embeds,要在富文本中插入图片或者视频需要使用insertEmbed api. insertEmbed insertEmbed(index: ...
- 现代富文本编辑器Quill的模块化机制
DevUI是一支兼具设计视角和工程视角的团队,服务于华为云DevCloud平台和华为内部数个中后台系统,服务于设计师和前端工程师.官方网站:devui.designNg组件库:ng-devui(欢迎S ...
随机推荐
- MySQL高级学习笔记(一):mysql简介、mysq linux版的安装(mysql 5.5)
文章目录 MySQL简介 概述 mysql高手是怎样炼成的 mysq linux版的安装(mysql 5.5) 下载地址 拷贝&解压缩 检查工作 检查当前系统是否安装过mysql 检查/tmp ...
- 极致CMS建站系统后台GETSHELL
起因 正在学习代码审计 看到有人提交了一个注入https://www.cnvd.org.cn/flaw/show/CNVD-2019-42775 想试试看还有没有别的漏洞 受影响版本 v1.6.3 - ...
- Mysql任意读取客户端文件复现
本机执行 python rogue_mysql_server.py 目标机器上连接本机数据库 mysql -u root -p -h 本机IP mysql -h 192.168.250.132 -ur ...
- activiti7从act_ge_bytearray表中查询资源文件并保存到桌面文件夹中
package com.zcc.activiti02; import org.activiti.engine.ProcessEngine;import org.activiti.engine.Proc ...
- Axon 3.0.x 框架简介官方文档
因为需要用到,但是在网上对应的资料实在是很少,只有迎着头皮看官网文档并配合翻译器.如有误导多多包涵. Axon 什么是 Axon Axon Framework 通过支持开发人员应用命令查询责任隔离(C ...
- javascript常用经典算法实例详解
javascript常用经典算法实例详解 这篇文章主要介绍了javascript常用算法,结合实例形式较为详细的分析总结了JavaScript中常见的各种排序算法以及堆.栈.链表等数据结构的相关实现与 ...
- Python之switch
首先声明,Python没有switch!!! 通过函数与字典的结合实现 #!/usr/bin/python #coding:utf-8 from __future__ import division ...
- 进程之间的通信AIDL
远程端: package cn.itcast.aidl; //AIDL //首先建立AIDL文件,有点和接口类似,建立好AIDL文件后, //会在gen文件夹下自动生成用于远程通信的类 //文件的后缀 ...
- idea的spring配置
开始使用idea,开始的时候把相关的插件都禁用了,导致在建项目和configuration的时候不出现spring相关字样 到plugins中找到installed的插件,查看spring boot ...
- Shell内置命令expr