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格式文件,其它瀏覽器沒有測試
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM