wx.request返回的是图片的二进制数据,如何用image控件将其显示出来?
发布于 5 年前 作者 xiayu 11077 次浏览 来自 问答

同标题

4 回复

wx.request里面把responseType设成arraybuffer,然后成功之后wx.arrayBufferToBase64(res.data)转成base64。

getValidateCode:function(){

    var that = this;

    wx.request({

        url: validateCodePath,

        method:‘get’,

        responseType: ‘arraybuffer’,

        success:function(res){

            const base64 = wx.arrayBufferToBase64(res.data);

            that.setData({

                validateCodePath: “data:image/png;base64,” + base64

            });

        }

    })

}

不行啊,发送的是获取小程序码的请求,我无法控制啊

wx.request({ //获取小程序码
          url: "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + getApp().globalData.access_token, //仅为示例,并非真实的接口地址
          header: {
            'content-type': 'application/json' // 默认值
          },
          data:{
            scene: json.content,
            page:"pages/news/detial",
            width:430
          },
          method:"POST",
          success: function (res) {
            var json = res.data;//获取的html文本信息
            console.log('小程序码:')
            console.log(res);
            // that.setData({img: json})
            wx.hideNavigationBarLoading();
          }
        })

你好,还有一个办法就是可以让后端直接返回图片链接给你哈,(#^.^#)

var that=this;

wx.downloadFile({

    url:’**********’

    success:function(e){

        that.setData({

                imgPath:e.

tempFilePath

        });

    }

})

<image src=’{{imgPaht}}’ />

这样不行吗?

回到顶部