feat: add one-click paste and upload image function

添加一键粘贴上传图片功能
This commit is contained in:
yanglbme 2019-12-23 22:34:38 +08:00
parent b81e6a46fe
commit cbbedeec90

View File

@ -72,10 +72,33 @@ let app = new Vue({
cm.showHint(e);
}
});
this.editor.on("change", (cm, change) => {
this.editor.on("change", (cm, e) => {
this.refresh();
this.saveEditorContent(this.editor, '__editor_content');
});
// 粘贴上传图片并插入
this.editor.on("paste", (cm, e) => {
if (!(e.clipboardData && e.clipboardData.items)) {
return;
}
for (let i = 0, len = e.clipboardData.items.length; i < len; ++i) {
let item = e.clipboardData.items[i];
if (item.kind === 'file') {
const pasteFile = item.getAsFile();
let data = new FormData();
data.append("file", pasteFile);
axios.post('https://imgkr.com/api/files/upload', data, {
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(resp => {
this.uploaded(resp.data)
}).catch(err => {
})
}
}
});
this.cssEditor.on('update', (instance) => {
this.cssChanged();
this.saveEditorContent(this.cssEditor, '__css_content');