feat: update images upload feature

更新图片上传功能
This commit is contained in:
yanglbme 2019-11-30 21:07:27 +08:00
parent f93a001507
commit 723a870ae3
2 changed files with 5 additions and 3 deletions

View File

@ -111,10 +111,11 @@ let app = new Vue({
// 图片上传结束
uploaded(response, file, fileList) {
if (response.success) {
// 上传成功
// 上传成功,获取光标
const cursor = this.editor.getCursor();
const imageUrl = response.data.url
const markdownImage = `![](${imageUrl})`
// 将 Markdown 形式的 URL 插入编辑框光标所在位置
this.editor.replaceSelection(`\n${markdownImage}\n`, cursor);
this.refresh();

View File

@ -34,9 +34,10 @@
<div id="app" class="container">
<el-container>
<el-header class="top">
<!-- 图片上传 -->
<el-upload action="https://cors-anywhere.herokuapp.com/https://sm.ms/api/v2/upload"
headers="{'Content-Type': 'multipart/form-data'}" :show-file-list="false" name="smfile" :on-success="uploaded"
:on-error="failed">
headers="{'Content-Type': 'multipart/form-data'}" :show-file-list="false" :multiple="false"
accept=".jpg,.jpeg,.png,.gif" :limit="1" name="smfile" :on-success="uploaded" :on-error="failed">
<i class="el-icon-upload" size="medium">&nbsp;</i>
</el-upload>
<el-form size="mini" class="ctrl" :inline=true>