post方式下载blob文件

handleExport () {    
      this.$http.post(url,params,{type: 'json',responseType:'blob' }).then(res => {
        const blob = new Blob([res], { type: 'application/x-download' });
        const fileName = "文件名.xlsx";
        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);
      }).catch(() => {
      })
    },

注意要添加  responseType:'blob'


版权声明:本文为zjx147原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。