code-farmer-i / vue-markdown-editor

A markdown editor built on Vue
https://code-farmer-i.github.io/vue-markdown-editor/
MIT License
1.1k stars 109 forks source link

如何使用多张图片上传? #227

Open lihuikun opened 1 year ago

XCLHove commented 8 months ago

这样写即可:

/**
     * @param e
     * @param insertImage
     * @param {File[]} files
     */
    async handleUploadImage(e, insertImage, files) {
      for (const file of files) {
        await this.upload(file).then(res => {
          insertImage({
            url: res.url,
            desc: res.desc
          });
        });
      }
    },
    /**
     * 模拟http请求上传图片
     * @param {File} file
     * @return {Promise<{url: string, desc: string}>}
     */
    upload(file) {
      return new Promise((resolve) => {
        resolve({
          url: file.name,
          desc: file.name,
        });
      });
    },