标签:通过 load document htm containe html 实现 undle 文件
js将html转为图片主要是通过html2canvas这个插件去操作的。具体实现如下:
html部分:
<!--index.html-->
<div id="container">
this is a test page!!!
<i></i>
<button onclick="download()">download</button>
</div>
<script src="./bundle.js"></script>
javascript部分:
//index.js import ‘./index.scss‘; import html2canvas from ‘html2canvas‘ window.download = () => { let container = document.getElementById(‘container‘) console.log(container) html2canvas(container).then(canvas => { let imgData = canvas.toDataURL() let link = document.createElement(‘a‘) link.href = imgData link.download = ‘test.png‘ link.click() }) }
利用html5的download属性实现文件下载
标签:通过 load document htm containe html 实现 undle 文件
原文地址:http://www.cnblogs.com/louis-sun/p/6820513.html