<a href="https://example.com/image.jpg" rel="external nofollow" download>下载图片</a>
// 下载图片 async downloadImage(e) { // 获取图片对象和画布对象 const imgUrl = https://example.com/image.jpg const response = await fetch(imgUrl) const blob = await response.blob() // 创建下载链接 const url = window.URL.createObjectURL(blob) const link = document.createElement('a') link.href = url link.download = 'image.png' document.body.appendChild(link) link.click() document.body.removeChild(link) // 释放 Blob URL window.URL.revokeObjectURL(url) }
来源:https://www.jb51.net/javascript/294186q23.htm
标签:vue,const,URL,url,link,blob,document,下载,图片 From: https://www.cnblogs.com/kpengfang/p/18120538