js使用a标签下载数据

通过a标签下载

exportText(ste) {
      const blob = new Blob([str])
      let date=new Date();
      const fileName = '下载案例.txt'
      const link = document.createElement('a') // 创建a标签
      link.download = fileName // a标签添加属性
      link.style.display = 'none'
      link.href = URL.createObjectURL(blob)
      document.body.appendChild(link)
      link.click() // 执行下载
      URL.revokeObjectURL(link.href) // 释放url
      document.body.removeChild(link) // 释放标签
    }

 

posted @ 2022-05-06 23:50  lijun12138  阅读(1267)  评论(0)    收藏  举报