Skip to content

Commit

Permalink
feat: add one-click paste and upload image function
Browse files Browse the repository at this point in the history
添加一键粘贴上传图片功能
  • Loading branch information
yanglbme committed Dec 23, 2019
1 parent b81e6a4 commit cbbedee
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion assets/scripts/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit cbbedee

Please sign in to comment.