vuede axios文件下载

this.loading = true;
this.$http({
baseURL: CLOUD_BASE_SERVER_URL,
          url: '/audit/auditRun/exportWord',
          method: 'get',
          responseType: 'blob',
          params: {
id: this.runId,
sumScoreRate: this.sumScoreRate
          }
        }).then(response => {
          this.loading = false
          var data = response.data;
  
          if (!data) {
            return
          }
  
          let url = window.URL.createObjectURL(new Blob([data]))
          let link = document.createElement('a');
          link.style.display = 'none';
          link.href = url;
          //设置新下载的文件名
          var downLoadFileName = '危险源登记.docx';
          link.setAttribute('download', downLoadFileName);
  
          document.body.appendChild(link);
          link.click();
        }).catch((error) => {
          console.log(error);
        });

转载于:https://www.cnblogs.com/zengdingxin/p/11268448.html

你可能感兴趣的:(vuede axios文件下载)