PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > HBuilderX教程 > 正文

    uniapp 显示后端返回的二进制流图片

    作者:admin来源:网络浏览:时间:2021-08-28 13:58:29我要评论
    导读:uniapp: this.$request是自己封装的 uni.request函数,responseType也需要写入封装函数
    uniapp: this.$request是自己封装的 uni.request函数,responseType也需要写入封装函数,具体见uniapp请求封装

    1. <template> 
    2.   <view> 
    3.     <!-- 显示图片的位置--> 
    4.     <image :src="QRImg"></image> 
    5.   </view> 
    6. </template> 
    7.  
    8. <script> 
    9.   export default { 
    10.     data() { 
    11.       return { 
    12.         QRImg: ''
    13.       } 
    14.     }, 
    15.     methods: { 
    16.       //获取图片 
    17.       async getImg() { 
    18.         const res = await this.$request('请求的url', { 
    19.           data: { 
    20.             "tablesid"this.orderId, 
    21.           }, 
    22.           responseType: "arraybuffer"//这是必要的一步,responseType必须设置为arraybuffer 
    23.         }) 
    24.         console.log(res, "kdkdkd"
    25.         const arrayBuffer = res.data 
    26.         //将arrayBuffer数据转换成base64格式即可显示 
    27.         this.QRImg = `data:image/jpeg;base64,${uni.arrayBufferToBase64(arrayBuffer)}` 
    28.       }, 
    29.     } 
    30. </script> 


    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-146-6609-1.html
    相关热词搜索: uniapp二进制流图片