Vue downloads PDF files: How does the front end convert the binary returned by the background into corresponding files

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)
                }

            });
        },

Reference link: https://blog.csdn.net/qq_37385617/article/details/108905361

Guess you like

Origin blog.csdn.net/qq_43907534/article/details/123232048