quill-image-extend-module的增强模块,在原有的功能上增强文件上传的灵活性
Installations
npm install quill-image-extend-module-enhanced
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
14.21.3
NPM Version
9.6.4
Score
72.8
Supply Chain
98.9
Quality
75.6
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (84.08%)
Vue (15.92%)
Developer
bigQY
Download Statistics
Total Downloads
665
Last Day
1
Last Week
3
Last Month
15
Last Year
109
GitHub Statistics
30 Commits
2 Branches
1 Contributors
Bundle Size
4.52 kB
Minified
1.76 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.2.4
Package Id
quill-image-extend-module-enhanced@1.2.4
Unpacked Size
33.49 kB
Size
6.55 kB
File Count
11
NPM Version
9.6.4
Node Version
14.21.3
Publised On
13 Apr 2023
Total Downloads
Cumulative downloads
Total Downloads
665
Last day
-50%
1
Compared to previous day
Last week
-72.7%
3
Compared to previous week
Last month
1,400%
15
Compared to previous month
Last year
-80.4%
109
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No dependencies detected.
sorry everyone, 由于作者自身原因,没有精力和时间处理issues,该插件已经不做维护了,希望大家见谅。
quill-image-extend-module
vue-quill-editor的增强模块,
功能:
- 提供图片上传到服务器的功能
- 复制插入
- 拖拽插入
- 显示上传进度
- 显示上传成功或者失败
- 支持与其他模块一起使用(例如调整图片大小)
更新情况
- version 1.1
- 增加上传显示文字样式
- 增加图片超过自定义大小的回调 sizeError
- 修复同一页面多个富文本编辑器上传图片只能插入第一个编辑器的bug
- 引入QuillWatch 全局监听多个富文本编辑器
- version 1.1.2
- 由于编辑器本身就有复制功能,因此取消了复制上传服务器的功能,避免冲突,复制上传采用富文本编辑器自带的功能
- 修复图片插入老是跑到最后面的问题
- version 1.2.0
- 增加自定义uploadhandler
Install
1npm install quill-image-extend-module-enhanced --save-dev
use
1 import {quillEditor, Quill} from 'vue-quill-editor' 2 import {container, ImageExtend, QuillWatch} from 'quill-image-extend-module-enhanced' 3 4 Quill.register('modules/ImageExtend', ImageExtend)
example
1<template> 2 <div class="quill-wrap"> 3 <quill-editor 4 v-model="content" 5 ref="myQuillEditor" 6 :options="editorOption" 7 > 8 </quill-editor> 9 </div> 10</template> 11<script> 12 import {quillEditor, Quill} from 'vue-quill-editor' 13 import {container, ImageExtend, QuillWatch} from 'quill-image-extend-module-enhanced' 14 15 Quill.register('modules/ImageExtend', ImageExtend) 16 export default { 17 components: {quillEditor}, 18 data() { 19 return { 20 content: '', 21 // 富文本框参数设置 22 editorOption: { 23 modules: { 24 ImageExtend: { 25 loading: true, 26 name: 'img', 27 action: updateUrl, 28 response: (res) => { 29 return res.info 30 } 31 }, 32 toolbar: { 33 container: container, 34 handlers: { 35 'image': function () { 36 QuillWatch.emit(this.quill.id) 37 } 38 } 39 } 40 } 41 } 42 } 43 } 44 } 45</script> 46
quill-image-extend-module 的所有可配置项
1 editorOption: { 2 modules: { 3 ImageExtend: { // 如果不作设置,即{} 则依然开启复制粘贴功能且以base64插入 4 name: 'img', // 图片参数名 5 size: 3, // 可选参数 图片大小,单位为M,1M = 1024kb 6 action: updateUrl, // 服务器地址, 如果action为空,则采用base64插入图片 7 // response 为一个函数用来获取服务器返回的具体图片地址 8 // 例如服务器返回{code: 200; data:{ url: 'baidu.com'}} 9 // 则 return res.data.url 10 response: (res) => { 11 return res.info 12 }, 13 headers: (xhr) => { 14 // xhr.setRequestHeader('myHeader','myValue') 15 }, // 可选参数 设置请求头部 16 sizeError: () => { }, // 图片超过大小的回调 17 start: () => { }, // 可选参数 自定义开始上传触发事件 18 end: () => { }, // 可选参数 自定义上传结束触发的事件,无论成功或者失败 19 error: () => { }, // 可选参数 上传失败触发的事件 20 success: () => { }, // 可选参数 上传成功触发的事件 21 change: (xhr, formData) => { 22 // xhr.setRequestHeader('myHeader','myValue') 23 // formData.append('token', 'myToken') 24 } // 可选参数 每次选择图片触发,也可用来设置头部,但比headers多了一个参数,可设置formData 25 useCustomUpload: true, // 可选参数 是否使用自定义上传,如果为true,则不会使用上面的上传方法 26 customUploadHandler: (file) => { // 可选参数 自定义上传方法,如果useCustomUpload为true,则必须设置此参数 27 // file为上传的图片文件 28 // 在此处可以使用axios等方法上传图片 29 } 30 }, 31 toolbar: { // 如果不上传图片到服务器,此处不必配置 32 container: container, // container为工具栏,此次引入了全部工具栏,也可自行配置 33 handlers: { 34 'image': function () { // 劫持原来的图片点击按钮事件 35 QuillWatch.emit(this.quill.id) 36 } 37 } 38 } 39 } 40 }
注意事项 (matters need attention)
由于不同的用户的服务器返回的数据格式不尽相同
因此 在配置中,你必须如下操作
1 // 你必须把返回的数据中所包含的图片地址 return 回去 2 respnse: (res) => { 3 return res.info // 这里切记要return回你的图片地址 4 }
比如你的服务器返回的成功数据为
1{ 2code: 200, 3starus: true, 4result: { 5 img: 'http://placehold.it/100x100' // 服务器返回的数据中的图片的地址 6 } 7}
那么你应该在参数中写为:
1 // 你必须把返回的数据中所包含的图片地址 return 回去 2 respnse: (res) => { 3 return res.result.img // 这里切记要return回你的图片地址 4 }
自定义上传
1<template> 2 <div class="quill-wrap"> 3 <quill-editor 4 v-model="content" 5 ref="myQuillEditor" 6 :options="editorOption" 7 > 8 </quill-editor> 9 </div> 10</template> 11<script> 12 import {quillEditor, Quill} from 'vue-quill-editor' 13 import {container, ImageExtend, QuillWatch} from 'quill-image-extend-module-enhanced' 14 import ImageResize from 'quill-image-resize-module' 15 16 Quill.register('modules/ImageExtend', ImageExtend) 17 // use resize module 18 Quill.register('modules/ImageResize', ImageResize) 19 export default { 20 components: {quillEditor}, 21 data() { 22 return { 23 content: '', 24 // 富文本框参数设置 25 editorOption: { 26 modules: { 27 ImageResize: {}, 28 ImageExtend: { 29 useCustomUpload: true, // 可选参数 是否使用自定义上传,如果为true,则不会使用quill自带的上传方法 30 customUploadHandler: (file) => { // 可选参数 自定义上传方法,如果useCustomUpload为true,则必须设置此参数 31 // file为上传的图片文件 32 // 在此处可以使用axios等方法上传图片 33 } 34 }, 35 toolbar: { 36 container: container, 37 handlers: { 38 'image': function () { 39 QuillWatch.emit(this.quill.id) 40 } 41 } 42 } 43 } 44 } 45 } 46 } 47 } 48</script>
(如果觉得还不错,请右上角点击下星星,此致敬礼)
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No security vulnerabilities found.