JS构造一个html文本内容成文件流形式发送到后台
具体代码如下所示:
let html = <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>X-Find迅聘选才</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/iview/2.14.0/styles/iview.css" rel="external nofollow" />
<style>
${resumecss}
</style>
</head>
<body>
<div class="resume_preview_page" style="margin:0 auto;width:1200px">
${template}
</div>
</body>
</html>;
var wordStream = window.URL.createObjectURL(
new Blob([html],{ type: "text/plain;charset=utf-8" }));
console.log('wordStream',wordStream);
let formdata = new FormData();
formdata.append('file',wordStream);
this.$post(url,formdata)
.then(res=>{
console.log('export finish',res);
})现在上面方式报错:

解决方法其实很简单
let html = this.getHtmlContent();
let html_ = new Blob([html],{ "type" : "text/html;charset=utf-8" })
let formdata = new FormData();
formdata.append('file', html_, `sdf.html`);
axios({
method: 'post',
url: url,
data:formdata,
responseType:'blob',
})总结
相关推荐
gufudhn 2020-06-06
nercon 2020-06-02
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
firstboy0 2020-06-14
e度空间 2020-06-12