鍍金池/ 問答/HTML/ js如何構(gòu)造一個html文本內(nèi)容成文件流形式發(fā)送到后臺?

js如何構(gòu)造一個html文本內(nèi)容成文件流形式發(fā)送到后臺?

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

現(xiàn)在上面方式報錯:

clipboard.png

回答
編輯回答
擱淺

自己已解決

            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',
            })
2017年11月7日 06:37