請求後臺得到文件流,下載後臺響應的文件流

  		var res=res;//接口響應的數據
  		 var elink = document.createElement('a');
          elink.download = "文件.xls";
          elink.style.display = 'none';
          var blob = new Blob([res],{type: 'application/vnd.ms-excel'});
          elink.href =  window.URL.createObjectURL(blob);
          document.body.appendChild(elink);
          elink.click();
          document.body.removeChild(elink);

當使用axios下載文件亂碼,解決方式如下:

 axios({
        method:'get',
        url:url,
        responseType:'arraybuffer'//重點是配置這裏
      })
        .then(function(response) {
          //響應結果
        });
    })
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章