vue2.0 下载 base64 图片教程

// 执行下载函数
// url_code base64编码数据
// 文件名称
downloadQrcode (url_code, img_name) {

      const blob = this.base64ToBlob('data:image/png;base64,' + url_code) // 转码
      const filename =  img_name
      const url = URL.createObjectURL(blob)
      const a = document.createElement('a')
      document.body.appendChild(a)
      a.href = url
      a.download = filename
      a.click()
    },
    base64ToBlob (code) {
      const parts = code.split(';base64,')
      const contentType = parts[0].split(':')[1]
      const raw = window.atob(parts[1])
      const rawLength = raw.length
      const uInt8Array = new Uint8Array(rawLength)
      for (let i = 0; i < rawLength; ++i) {
        uInt8Array[i] = raw.charCodeAt(i)
      }
      return new window.Blob([uInt8Array], { type: contentType })
    },
发表评论 / Comment

请登录后发表评论