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; },