vue-pdf接收文件流
pdfDlg: function() {
axios({
method: 'GET',
url: '/web/pdfFile', // 后台接口
paramsSerializer: function(params) {
return qs.stringify(params, { arrayFormat: 'brackets' })
},
headers: {
'Content-Type': 'application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet'
},
responseType: 'blob'
}).then(response => {
this.src = this.getObjectURL(response.data)
this.pdfCurrentPage = 1 // 首先加载第一页
this.pdfDlgVisible = true
}).catch(error => { this.$message.error('' + error) })
},
// 处理文件流
getObjectURL(file) {
let url = null
if (window.createObjectURL !== undefined) { // basic
url = window.createObjectURL(file)
} else if (window.webkitURL !== undefined) { // webkit or chrome
try {
url = window.webkitURL.createObjectURL(file)
} catch (error) {
console.log(error)
}
} else if (window.URL !== undefined) { // mozilla(firefox)
try {
url = window.URL.createObjectURL(file)
} catch (error) {
console.log(error)
}
}
return url
},