【发布时间】:2017-10-07 00:43:30
【问题描述】:
从这里使用编辑器: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);
});
},
我试过这个:Add support for custom image handler 但它不起作用,因为 image 总是 true 并且回调是未定义的。
也试过这个:Quill imageHandler Demo
第一个链接也有同样的问题。
当前服务器被硬编码为返回“http://localhost/images/php.jpg”
如果可能,我不会使用任何库(jQuery、dropzone 等)
我想我也许可以检查一下图像是否插入到 onEditorChange() 中,然后向服务器发送请求,获取 URL,在编辑器中搜索这个 base64 并将其替换为 URL,但它似乎不正确。
【问题讨论】:
标签: javascript image vuejs2 quill