vue项目里面预览下载附件
// 预览附件
handlePreview(file) {
console.log(file);
if (file.name.indexOf("txt") == "-1") {
const link = document.createElement("a");
document.body.appendChild(link);
link.style.display = "none";
link.setAttribute(
"href",
file.url + "?response-content-type=application/octet-stream"
); //设置下载文件的url地址
link.target = "_blank";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} else {
let element = document.createElement("a");
element.setAttribute(
"href",
"data:text/plain;charset=utf-8," + file.url
);
element.setAttribute("download", file.name);
element.style.display = "none";
element.click();
}
}
ppt、pptx、doc、docx、pdf、xls、xslx、rar、txt、zip