Posted in Javascript onJuly 31, 2018
具体代码如下所示:
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', })
总结
以上所述是小编给大家介绍的JS构造一个html文本内容成文件流形式发送到后台,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!
JS构造一个html文本内容成文件流形式发送到后台
- Author -
Awbeci声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@