<iframe :src="fileURLOther">iframe>
import axios from "axios";
data() {
return {
fileURLOther: "",
url:'',
id:''
}
}
methods:{
openPDF() {
axios({
method: "get",
url: this.url,//文件的url
params: {
fileId: this.id,//文件的id
},
responseType: "blob",// 设置返回类型
}).then((res) => {
let blob = new Blob([res.data], {
type: "application/pdf;chartset=UTF-8",
});
this.fileURLOther = URL.createObjectURL(blob);
});
},
}
<el-button @click="openPDF"> 预览 el-button>