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" />
                    <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);
                
            })

现在上面方式报错:

clipboard.png

阅读 3.4k
1 个回答

自己已解决

            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',
            })
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
1 篇内容引用
推荐问题
宣传栏