当前位置:网站首页>Enhanced paste quill editor
Enhanced paste quill editor
2022-06-25 05:09:00 【Lijianyi】
Kung Fu brothers can have a look at my Blog www.maple.ink
Paste picture into rich text
Drag and drop the image directly to rich text , Or copy image files from the system , Paste in rich text , Can't put pictures into rich text . The former will open a new window directly in the browser , The latter has no direct reaction .
Through installation quill-image-extend-module The enhancement module enables the rich text editor to drag and drop pictures into the rich text box , But it does not have the function of copying and pasting into rich text . It can cooperate with quill-image-resize-module The module sets the size of the picture .
// Introduce picture enhancement module
import {
container, ImageExtend, QuillWatch} from 'quill-image-extend-module'
Quill.register('modules/ImageExtend', ImageExtend)
// The picture control enhancement module is introduced
import ImageResize from 'quill-image-resize-module'
Quill.register('modules/ImageResize', ImageResize)
export default {
data() {
return {
editorOptions: {
modules: {
ImageExtend: {
loading: true,
name: 'img',
action: '',
headers: (xhr) => {
},
response: (res) => {
return res.info
}
},
ImageResize: {
modules: [ 'Resize', 'DisplaySize', 'Toolbar' ]
},
}
}
}
}
}

Be careful : Although this method has the function of displaying pictures in rich text boxes , But the principle is actually to get the picture file object , adopt FileReader Object to convert it to base64 Format , Put in img Of src Properties of the , Therefore, theoretically speaking, it does not have the ability to transfer large files , There may also be some degree of distortion .
Paste file into rich text
The main principle of pasting a file is to bind the paste event of the current rich text box , Get the pasted by pasting the event file object .
// Introduce custom formats
import uploadFile from './quillPlus/uploadFile';
uploadFile.blotName = 'uploadFile';
uploadFile.tagName = 'div';
Quill.register(uploadFile);
methods: {
onEditorFocus() {
let quill = this.$refs.editor.quill,
self_ = this;
// Listen for paste events
quill.root.addEventListener('paste', (event)=> {
// Determine whether the pasted picture is
if(event.clipboardData && event.clipboardData.files && event.clipboardData.files) {
// Prevent native Events
event.preventDefault();
let cursorIndex = quill.selection.savedRange.index;
[].forEach.call(event.clipboardData.files, file => {
// Determine whether the current file is a picture
if(file.type.match(/^image\/(gif|jpe?g|a?png|bmp)/i)) {
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(e) {
quill.insertEmbed(cursorIndex, 'image', e.target.result);
}
}else {
// Notice here because insertEmbed Statements can only be inserted into rich text in a well-defined format , So we need to extend the current format
quill.insertEmbed(cursorIndex, 'uploadFile', {
file: file, fileIndex: self_.fileIndex++});
}
})
}
});
},
}
Custom format components
import {
Quill} from 'vue-quill-editor';
const BlockEmbed = Quill.import('blots/block/embed');
class uploadFile extends BlockEmbed {
static create(value) {
let node = super.create();
// Set up a class Class name controls style
node.setAttribute('class', 'upload-file');
// Setting does not allow operation
node.setAttribute('contentEditable', false);
// Set up data-id Mark
node.setAttribute('data-id', value.fileIndex);
node.innerText = value.file.name;
return node;
}
static value(node) {
return {
dataId: node.getAttribute('data-id')
}
}
}
export default uploadFile;
This solution can also solve the problem of uploading pictures , Especially big pictures .
Be careful : There are two solutions for uploading files :
- Paste the file into rich text to trigger uploading , adopt HTTP Requesting a direct call to the interface will file Object to fromData Deliver to the server . After receiving the file, the server returns the link of the current file on the server , Insert link into page DOM On the property of .
- Paste the file into the rich text and the current file Object into an array , Click the upload button to upload to the server through the loop .
The first solution is recommended for uploading files , as a result of : Easy front end ~

边栏推荐
- Precise delay based on Cortex-M3 and M4 (systick delay of system timer can be used for STM32, aducm4050, etc.)
- Five simple data types of JS
- Activereportsjs V3.0 comes on stage
- Redis (17)
- Bind simulation, key points of interpreting bind handwritten code [details]
- A review of small sample learning
- How to install the blue lake plug-in to support Photoshop CC 2017
- In depth understanding of line height and vertical align
- Database overview
- Eyeshot Ultimate 2022 Crack By Xacker
猜你喜欢

Working principle of asemi three-phase rectifier bridge

hr竟主动给这位测试小姐姐涨工资,她是怎么做到的?

Various pits encountered in the configuration of yolov3 on win10

渗透测试-目录遍历漏洞

Go deep into the working principle of browser and JS engine (V8 engine as an example)

Personalized Federated Learning with Moreau Envelopes

Difference between asemi high power FET and triode

Five simple data types of JS
![H5 native player [learn video]](/img/51/83a200d0423b7274d1e981ec2ede2c.jpg)
H5 native player [learn video]

The construction and usage of wampserver framework
随机推荐
Why does the SQL statement hit the index faster than it does not?
Specific operations for uploading pictures in PHP
OLAP analysis engine kylin4.0
电脑的dwg文件怎么打开
Reading and writing of nodejs excel (.Xlsx) files
Mobile number regular expression input box loses focus verification
Eyeshot 2022 Released
The SQL response is slow. What are your troubleshooting ideas?
Could not find “store“ in the context of “Connect(homePage)
Go deep into the working principle of browser and JS engine (V8 engine as an example)
Redis (17)
File upload vulnerability (III)
parallel recovery slave next change & parallel recovery push change
Compatible with Internet Explorer
What is Ethernet and how to connect the computer
Abuse unlimited authorization -- is your address safe?
great! Auto like, I use pyautogui!
[keil] GPIO output macro definition of aducm4050 official library
For in JS Of and for in
ASEMI大功率场效应管和三极管的区别