Vue.js html2canvas截取图片并下载

编程入门 行业动态 更新时间:2024-10-19 00:25:17

Vue.js html2canvas截取<a href=https://www.elefans.com/category/jswz/34/1770705.html style=图片并下载"/>

Vue.js html2canvas截取图片并下载

首先官网的链接地址  /

一、在工程下引入   npm install --save html2canvas

                                

import html2canvas from 'html2canvas';

 

        <div id="mymap" style="width:100%;height:100%;position: relative;"><div id="mapDiv"></div><baseMap></baseMap></div>
//导出createPicture() {html2canvas(document.getElementById('mymap')).then(canvas => {this.imgmap = canvas.toDataURL()console.log(999, this.imgmap)if (window.navigator.msSaveOrOpenBlob) {var bstr = atob(this.imgmap.split(',')[1])var n = bstr.lengthvar u8arr = new Uint8Array(n)while (n--) {u8arr[n] = bstr.charCodeAt(n)}var blob = new Blob([u8arr])window.navigator.msSaveOrOpenBlob(blob, 'chart-download' + '.' + 'png')} else {// 这里就按照chrome等新版浏览器来处理const a = document.createElement('a')a.href = this.imgmapa.setAttribute('download', 'chart-download')a.click()}});},

 

更多推荐

Vue.js html2canvas截取图片并下载

本文发布于:2024-03-06 14:29:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1715550.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图片   Vue   js   html2canvas

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!