1. let that = this
    2. this.$confirm('确认导出?', '提示', {
    3. confirmButtonText: '确定',
    4. cancelButtonText: '取消',
    5. type: 'warning'
    6. }).then(function () {
    7. that.loading = true;
    8. var paramData = that.form;
    9. var xhr = new XMLHttpRequest();
    10. var url = Domain + "/sysback/price/goodsprice/exportGoodsPrice";
    11. xhr.open('POST', url, true);
    12. // 设置请求头参数,可以添加token值
    13. xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
    14. // 设置响应体返回类型,这里需要把返回的文件流转换成 blob 类型
    15. xhr.responseType = 'blob';
    16. xhr.onload = function (e) {
    17. if (this.status == 200) {
    18. that.loading = false;
    19. // 这里从 响应头里面取出 文件名称,根据实际情况操作
    20. var name = xhr.getResponseHeader('Content-disposition');
    21. name = decodeURIComponent(name);
    22. // 这里对文件名进行操作,是根据实际情况操作的
    23. var fileName = name.substring(20, name.length);
    24. // 返回的文件流,转换成blob对象
    25. var blob = new Blob([xhr.response]);
    26. // 转换成blob类型的url
    27. var blobUrl = URL.createObjectURL(blob);
    28. // 模拟 a 标签进行下载
    29. var eLink = document.createElement('a');
    30. // 设置 a 标签的展示方式,默认 display:none
    31. eLink.style.display = 'none';
    32. // 设置 a 标签的 url
    33. eLink.href = blobUrl;
    34. // 设置 下载文件的文件名称
    35. eLink.download = fileName;
    36. document.body.appendChild(eLink);
    37. eLink.click();
    38. document.body.removeChild(eLink);
    39. }
    40. };
    41. xhr.send(JSON.stringify(paramData));
    42. }).catch(function () {
    43. that.$message({
    44. type: "info",
    45. message: "已取消导出"
    46. });
    47. });