使用这里的编辑器:https://github.com/surmon-china/vue-quill-editor
我想将Quill编辑器中的图片保存到MySQL数据库,但是在base64中较大的图片太长而无法插入。
我尝试编写自定义图像处理程序,使其自动将图像上传到服务器并返回图像URL,但现在我被卡住了。
这是我的当前HTML:
<quill-editor v-model="content"
:options="editorOption"
@onEditorBlur($event)"
@onEditorFocus($event)"
@onEditorReady($event)"
@onEditorChange($event)">
</quill-editor>
像这样将图像处理程序添加到编辑器中:
onEditorReady(editor) {
editor.getModule('toolbar').addHandler('image', this.imageHandler);
console.log('editor ready!', editor);
},
还有我自己的处理程序:
imageHandler(image, callback){
console.log(image); // Always true
console.log(callback); // Always undefined
// Should get image in here somehow..
var sendData = {
image: 'SomethingShouldBeInHere',
};
// Send image to server,
// Server will return link to image
axios.put('/testImageUpload', sendData)
.then(function(cbData) {
// In here should add image tag to editor somehow..
})
.catch(function (error) {
console.log(error);
});
},
我尝试了这个:添加支持自定义图像处理程序,但它不起作用,因为图像始终为true且回调未定义。
也尝试了这个:Quill imageHandler
演示,但遇到了与第一个链接相同的问题。
目前服务器是硬编码返回 "http://localhost/images/php.jpg"。
如果可能,我将不使用任何库(jQuery、dropzone等)。
我想,也许可以在onEditorChange()中检查是否插入了图像,然后发送请求到服务器,获取URL,在编辑器中搜索此base64并将其替换为URL,但这似乎不正确。