downloadFile() {
      let url = '' //具体的文件地址
      let name = url.split('?')[0].split('/')
      let filename = name[name.length - 1];
      fetch(url, {
        headers: new Headers({
          Origin: location.origin,
        }),
        mode: 'cors',
      })
        .then(res => res.blob())
        .then(blob => {
          const blobUrl = window.URL.createObjectURL(blob)
          this.download(blobUrl, filename)
          window.URL.revokeObjectURL(blobUrl)
        })
    },
    download(href, filename) {
      const a = document.createElement('a')   
      a.download = filename
      a.href = href
      a.target="_blank"
      document.body.appendChild(a)  
      a.click()
      a.remove()
    },
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐