Vue 下载PDF文件:前端如何将后台返回的二进制转换成对应的文件

download(val) {
            carFindWord(val.id).then((res) => {
                let blob = new Blob([response.data], {type: 'application/pdf'})
                let fileName = Date.parse(new Date()) + '.pdf'
                if (window.navigator.msSaveOrOpenBlob) {
                    navigator.msSaveBlob(blob, fileName)
                } else {
                    var link = document.createElement('a')
                    link.href = window.URL.createObjectURL(blob)
                    link.download = fileName
                    link.click()
                    //释放内存
                    window.URL.revokeObjectURL(link.href)
                }

            });
        },

参考链接:https://blog.csdn.net/qq_37385617/article/details/108905361

猜你喜欢

转载自blog.csdn.net/qq_43907534/article/details/123232048