axios 或 ajax 请求文件

axios 或 ajax 请求文件

 axios({
        url: path + '/monitor/exportPicture' + '?access_token=' + getToken(),
        method: 'post',
        type: 'application/zip',
        data: this.pptFormInfo,
        responseType: 'blob'
      }).then(response => {
        const blob = new Blob([response.data])
        const fileName = this.schemeName + '.zip'
        if ('download' in document.createElement('a')) { // 非IE下载
          const elink = document.createElement('a')
          elink.download = fileName
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob)
          document.body.appendChild(elink)
          elink.click()
          URL.revokeObjectURL(elink.href) // 释放URL 对象
          document.body.removeChild(elink)
          this.disable = false
        } else { // IE10+下载
          navigator.msSaveBlob(blob, fileName)
          this.disable = false
        }
      })

猜你喜欢

转载自www.cnblogs.com/dw3306/p/10749900.html