后端返回字节流文件,前端应该怎样进行预览与下载,目前只有(txt、pdf、png三种)
一、预览
async yulan(row) {
if (row.docName == “” || row.docExt == “”) {
this.$message.error(“找不到文件”);
return false
}
if(row.docExt == “txt”){
let url = “/File/DownLoad”;
let param = {
id: row.attchmentId,
},
responseType = “DOMString”; //为了解决乱码
getData(url, param, responseType).then((res) => {
let changeUrl = "";
if (res.status == 200) {
const blob = new Blob([res.data], {type: 'application/json;charset=utf-8'});//转成txt类型
const dlink = document.createElement("a");
if ("download" in document.createElement("a")) {
// 非IE下载
const dlink = document.createElement("a");