const html = `导出的测试文字`;
const htmlDom = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>标题</title>
</head>
<body>
<div class="t-l" style="width:1200px">
${html}
</div>
</body>
</html>`;
const htmlDom_ = new Blob([htmlDom], { "type": "text/html;charset=utf-8" })
const formdata = new FormData();
formdata.append('file', htmlDom_, `sdf.html`);//sdf.html是设置文件名
// axios({
// method: 'post',
// url: url,
// data: formdata,
// responseType: 'blob',//这里如果不设置,下载会打不开文件
// }).then(res => {
// console.log('download res', res);
// 通过后台返回 的word文件流设置文件名并下载
const blob = new Blob([htmlDom], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8' }); //application/vnd.openxmlformats-officedocument.wordprocessingml.document这里表示doc类型
const downloadElement = document.createElement('a');
const href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
downloadElement.download = `${data.tempName}.doc`; //下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放掉blob对象
data.visible = false;//释放掉model