() color can 实现 data url pan his
js 将 html 转为图片主要是通过 html2canvas 这个插件去操作的。具体实现如下:
html 部分:
- thisis a test page!!!
- download
javascript 部分:
- //index.jsimport './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 属性实现文件下载
javascript 将 html 转为图片保存。
来源: http://www.bubuko.com/infodetail-2057593.html