1,word下载功能
word(url, data).then((res) => {
const url=window.URL.createObjectURL
(newBlob([res.data]));
const aLink = document.createElement("a");
aLink.href = url;
const name = "xxxxx.docx";
aLink.setAttribute("download", name);
document.body.appendChild(aLink);
aLink.click();
window.URL.revokeObjectURL(aLink.href);
document.body.removeChild(aLink);
});
export const word = (url, data) => {
return axios.request({
url,
data,
isLoading: true,
isRequestTip: false,
method: "post",
responseType: "blob",
})
}
2,pdf预览功能
pdf({ url, data).then((res) => {
const jsonData = res.data;
this.showModal = true;
const blob = new Blob([jsonData], { type:"application/pdf"});
const url = window.URL.createObjectURL(blob);
this.previewUrl = url;
});
export const pdf= (url,data) => {
return axios.request({
url,
data,
method: "post",
responseType: 'blob',
isXssTest: false
});
};
<Modal
title="预览文件"
v-model="showModal"
:width="'80%'"
:height="'800px'"
>
<iframe
:src="previewUrl + '#toolbar=0'"
width="100%"
height="500px"
style="overflow: auto"
></iframe>
</Modal>