vue 导出html

vue的html代码

<template>
<div class="contentsss" ref="test">
<button @click="export2Excel">导出</button>
</div>
</template>

  

 

methods方法

export2Excel() {
var a = document.createElement("a");
var url = window.URL.createObjectURL(
new Blob([this.gethtml()], {
type: ''
})
);
a.href = url;
a.download = "file.html";
a.click();
window.URL.revokeObjectURL(url);
}

gethtml() {
const template = this.$refs.test.innerHTML;
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" />
 
</head>
<body>
<div class="resume_preview_page" style="margin:0 auto;width:1200px">
${template}
</div>
</body>
</html>`;
return html;
},

  

 
在谷歌浏览器亲测可以导出html格式文件,其它浏览器没有测试
 
 
posted @ 2019-08-13 13:29  时光如瑾季微凉  阅读(5256)  评论(0编辑  收藏  举报