动态生成html,txt,文件转file格式
<script>
methods: {
async reportSumbit() {
let content = document.getElementsByClassName('ck-editor__main')[0].innerHTML;
let link = '<link type="text/css" rel="stylesheet" href="' + this.BASE_URL + 'editor.css">'
this.html = `<!DOCTYPE html>
<html lang="en">
<head>
${link}
</head>
<body>
${content}
</body>
</html>`;
let urlObject = window.URL || window.webkitURL || window;
let export_blob = new Blob([this.html], {
type: "text/html",
});
console.log(export_blob)
var save_link = document.createElement("a")
save_link.href = urlObject.createObjectURL(export_blob);
save_link.download = name;
save_link.click();
},
},
blobToFile(blob, fileName) {
const file = new File([blob], fileName, { type: blob.type });
return file;
},
</script>