vue中通过url实现下载pdf
安装:npm install file-saver --save让后端返回[blob]文件格式,需要传递 responseType: ‘blob’axios({url: url, // 服务器上pdf路径method: 'get',responseType: 'blob'}).then(res => {// eslint-disable-next-line no-undef// consol
·
安装:
npm install file-saver --save
让后端返回[blob]文件格式,需要传递 responseType: ‘blob’
axios({
url: url, // 服务器上pdf路径
method: 'get',
responseType: 'blob'
}).then(res => {
// eslint-disable-next-line no-undef
// console.log(res)
const FileSaver = require('file-saver')
const blob = new Blob([res], { type: 'application/pdf;charset=utf-8' }) // 此处type根据你想要的
FileSaver.saveAs(blob, name) // 下载的name文件名
}).catch(err => {
// eslint-disable-next-line no-undef
console.log(err)
})
更多推荐
所有评论(0)