试试利用canvas保存图片,分享下方法:
//确定图片的类型 获取到的图片格式 data:image/Png;base64,...... let type = 'jpeg'; let canvas = this.$refs['ent-rela-echart'].querySelector('canvas'); let imgdata = canvas.toDataURL(type, 1.0); //将mime-type改为image/octet-stream,强制让浏览器下载 let fixtype = function (type) { type = type.toLocaleLowerCase().replace(/jpg/i, 'jpeg'); let r = type.match(/png|jpeg|bmp|gif/)[0]; return 'image/' + r; }; imgdata = imgdata.replace(fixtype(type), 'image/octet-stream'); //将图片保存到本地 let savaFile = function (data, filename) { let save_link = document.createElement('a'); save_link.href = data; save_link.download = filename; let event = new MouseEvent('click'); save_link.dispatchEvent(event); }; let filename = '' + new Date().getSeconds() + '.' + type; //用当前秒解决重名问题 savaFile(imgdata, filename);
网友评论文明上网理性发言 已有0人参与
发表评论: