1. function downFile(res, fileName) {
    2. const blob = new Blob([res], {
    3. type: `application/pdf;charset=UTF-8`
    4. });
    5. if (window.navigator.msSaveOrOpenBlob) {
    6. // 兼容ie11
    7. window.navigator.msSaveOrOpenBlob(blob, fileName);
    8. } else {
    9. const url = URL.createObjectURL(blob);
    10. const downloadElement = document.createElement("a");
    11. downloadElement.href = url;
    12. downloadElement.download = fileName;
    13. document.body.appendChild(downloadElement);
    14. downloadElement.click();
    15. downloadElement.remove();
    16. URL.revokeObjectURL(url);
    17. }
    18. }
    19. try {
    20. this.$http.post("/api/company/bill/download", {
    21. id,
    22. }, {
    23. responseType: 'blob'
    24. }).then((res) => {
    25. this.showLoading = false;
    26. downFile(res, `123.pdf`)
    27. return;
    28. });
    29. } catch (error) {
    30. console.error('error: ', error);
    31. }

    重点在于responseType: ‘blob’,指定已blob形式接收。
    接口返回的大致如下:
    image.png