Vue拿到二进制流图片转为正常图片并显示

第一步

axios({
        method: 'get',
        url,
        responseType: 'arraybuffer' // 最为关键
      })
        .then(function (response) {
          that.src = 'data:image/jpeg;base64,' + that.arrayBufferToBase64(response.data)
        })
arrayBufferToBase64 (buffer) {
      var binary = ''
      var bytes = new Uint8Array(buffer)
      var len = bytes.byteLength
      for (var i = 0; i < len; i++) {
        binary += String.fromCharCode(bytes[i])
      }
      return window.btoa(binary)
    },
 <img :src="src" alt="验证码">

你可能感兴趣的:(vue,前端知识,javascript,vue.js)