<div>
<span href="" download="" class="text-right" @click="download">下载</span>
<a id="download" href=""></a>
</div>
download(){
let sampleImage = $('.qrcode img')[0] // 找到图片所在的img标签
var canvas = this.convertImageToCanvas(sampleImage); //创建画板
var url = canvas.toDataURL("image/png"); //生成下载的url
var triggerDownload = $("#download").attr("href", url).attr("download", "ewm.png"); // 把url放到我们的a标签中,并得到a标签对象
triggerDownload[0].click(); //模拟点击一下a标签,即可下载啦!
},
convertImageToCanvas(image) {
var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
canvas.getContext("2d").drawImage(image, 0, 0);
return canvas;
},
base64格式图片下载功能
最新推荐文章于 2024-08-23 13:58:07 发布