JS a标签文件下载

 

    aDownload(url, fileName) {

      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = url
      link.download = fileName
      // link.setAttribute('download', fileName)
      document.body.appendChild(link)
      link.click() // a标签自动触发点击事件
      link.remove()
   
document.body.removeChild(link)
      window.URL.revokeObjectURL(url) // 释放url
    },

 

posted @ 2022-11-07 15:11  非帆丶  阅读(432)  评论(0编辑  收藏  举报