实现在线预览PDF文件、图片,并且预览地址不显示文件或图片的真实路径。
1、vue使用blob流在线预览PDF、图片(包括jpg、png等格式)。
想要实现在线预览PDF文件、图片,并且预览地址不显示文件或图片的真实路径,可使用blob流。
vue前端关键代码:
1、按钮的方法:
<el-button color="#00ffcc" size="small" @click="invoicePreview(props.row.oid)" v-if="props.row.ifInvoice == 1"><el-icon><Tickets /></el-icon>查看发票</el-button>
2、方法详细:(此方法可以在发起请求时携带token,适合JWT认证)
// 预览发票
invoicePreview(oid){
console.log(oid)
this.$http({
url: 'invoicePreview',
method: 'get',
responseType: 'arraybuffer',
params: {
oid: oid
}
}).then(res => {
console.log(res);
console.log(res.headers.type);
let fileType = res.headers.type;
let currType = '';
const binaryData = [];
if(fileType){
currType = fileTypeMap[fileType]
if(this.imageType.includes(fileType)){
// 识别为图片
binaryData.push(res.data);
//获取blob链接
this.URL = window.URL.createObjectURL(new Blob(bin
4933



被折叠的 条评论
为什么被折叠?



