vue接口预览文件
import axios from "axios"
methods:{
getfile(){
axios({
method:"post",
url:"",
headers:{
"Content-Type":"application/json"
},
responseType:"arraybuffer",
transformRequest:[
function(data){
data:JSON.stringify(data)
return data
}
],
data:{}
}).then(res=>{
var data = new Unit8Array(res.data);
var workbook=XLSX.read(data,{type:"array"});
var sheetNames= workbook.SheetNames;
var worksheet=workbook.Sheets[sheetNames[0]]
this.tableau=XLSX.utils.sheet_to_html(worksheet)
})
},
axios
.request({
method: "GET",
url: '后端地址'
responseType: "blob",
})
.then((res) => {
console.log(res);
if (res) {
let docx = require("docx-preview");
docx.renderAsync(res.data, this.$refs.file);
} else {
that.$notify.error({ title: "失败", message: "接口请求失败" });
that.loading = false;
}
})
.catch(function (error) {
that.$notify.error({ title: "失败", message: "接口请求失败" });
console.log(error);
that.loading = false;
});
}
this.dialogVisible = true;
},
axios
.request({
method: "GET",
url: '后端接口',
responseType: "blob",
headers: {
Accept: "application/octet-stream",
},
})
.then((res) => {
console.log(res);
if (res) {
let blob = new Blob([res.data], { type: "image/jpeg" });
const imageUrl = URL.createObjectURL(blob);
this.imgUrl = imageUrl;
this.srcList = [imageUrl],;
that.loading = true;
axios
.request({
method: "GET",
url: '后端地址'
responseType: "blob",
headers: {
"Content-Type": "application/pdf;charset=UTF-8",
},
})
.then((res) => {
console.log(res);
if (res) {
let blob = new Blob([res.data], { type: "application/pdf" });
const url = URL.createObjectURL(blob);
console.log(url);
that.loading = false;
this.pdfurl = url;