element ui 里面的表格 导出word形式 直接下载到本地

发布时间 2023-07-01 15:11:24作者: 张二十

 干吧家人们

 

 

可以根据后端返回的接口里面的地址直接把他下载下来

 

可以使用

let link = document.createElement('a');

let objectUrl = res.data.path; //重要重要的是这个 这个是后端返回回来的地址

link.setAttribute("href", objectUrl);

link.setAttribute("download",'订单.docx');
link.click();//释放内存

window.URL.revokeObjectURL(link.href)

 

如果后端返回的是 word 文档里面的数据

可以使用

printOrder(id) {
console.log(id)

orderPrintApi(id,{   //封装的接口地址

responseType:'blob',

headers: {'Content-Type': 'application/x-www-form-urlencoded  '}
}

.then((res) => [

// console.log()console.log(res .message. respnse.data)

let blob = new Blob([res],{
type: 'application/vnd.ope
xmlformats-officedocument .wordprocessingml .document;charset=UTF-8'})


let link = document.createElement('a');
// link.download = fileName//a标签添加属性
let objectUrI = URL.createobjectURL(blob).
console.log(objectUr1)
link.setAttribute("href", objectUrl);
link.setAttribute("download","订单.docx');
118
link.click();
//释放内存
window.URL.revokeObjectURL(link.href)
})

},