vue 下载图片

<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

posted @ 2024-04-08 10:11  kpengfang  阅读(433)  评论(0编辑  收藏  举报