zoukankan      html  css  js  c++  java
  • Vue根据后端返回base64转成图片并下载

    //qrBase64是后台传回来的base64数据
    handleDownloadQrIMg(qrBase64) {
          // 这里是获取到的图片base64编码,这里只是个例子哈,要自行编码图片替换这里才能测试看到效果
          const imgUrl = `data:image/png;base64,${qrBase64}`
          // 如果浏览器支持msSaveOrOpenBlob方法(也就是使用IE浏览器的时候),那么调用该方法去下载图片
          if (window.navigator.msSaveOrOpenBlob) {
            const bstr = atob(imgUrl.split(',')[1])
            let n = bstr.length
            const u8arr = new Uint8Array(n)
            while (n--) {
              u8arr[n] = bstr.charCodeAt(n)
            }
            const blob = new Blob([u8arr])
            window.navigator.msSaveOrOpenBlob(blob, 'chart-download' + '.' + 'png')
          } else {
            // 这里就按照chrome等新版浏览器来处理
            const a = document.createElement('a')
            a.href = imgUrl
            a.setAttribute('download', 'chart-download')
            a.click()
          }
    }
    
  • 相关阅读:
    senium
    学习记录
    方法参数化
    洛谷1892 团伙
    洛谷2661 信息传递
    洛谷2661 信息传递
    洛谷1576最小花费
    洛谷1576最小花费
    最短路 Dijkstra模板
    堆排(模板)
  • 原文地址:https://www.cnblogs.com/qingheshiguang/p/15406854.html
Copyright © 2011-2022 走看看