Vue使用axios请求处理图片流

that.axios.get('http://192.168.99.99:8000/msg?app=TG&t=numid&v=xxxxxxxx>e=0&dtype=day&stamp=xxxxxxxxx&format=png', {
     
    responseType: "arraybuffer",//这里是声明期望返回的数据类型
}).then(function (response) {
     
    //将从后台获取的图片流进行转换
    return 'data:image/png;base64,' + btoa(
        new Uint8Array(response.data).reduce((data, byte) => data + String.fromCharCode(byte), '')
    );
}).then(function (data) {
     
    //接收转换后的Base64图片
    console.log(data);
}).catch(function (error) {
     
    // this.$message.error(error);
})

你可能感兴趣的:(javascript,vue.js,npm)