图片存在腾讯云里的,获取图都需要一个个拼接URL,小程序里打印出来数组里有值,但页面image标签的src显示为空。
<block wx: for = "{{items}}" wx:key= "id" > <view id= '{{index}}' class= "view-item" > <image src= '{{outcarImgIdArr[index]}}' mode= "widthFix" ></image> </view>
data: { outcarImgIdArr:[] }, showImgs:function (item) { let that = this; let isnum = 0 if (isnum < item.length) { http.getAuthor({ Method: 'get', Key: item[isnum].outcarImgId }).then((auth) => { //url地址为 let getPath = 'https://' + config.Bucket + '.cos.' + config.Region + '.myqcloud.com' + '/' + item[isnum].outcarImgId + '?sign=' + encodeURIComponent(auth); if (that.data.outcarImgIdArr.length < 5) { that.data.outcarImgIdArr.splice(isnum, 1, getPath); } else { that.data.outcarImgIdArr = that.data.outcarImgIdArr.concat(getPath); } isnum += 1; console.log(that.data.outcarImgIdArr) that.showImgs(item) }).catch((err) => { console.log(err); }) } |
网友回复
that.setData({outcarImgIdArr :that.data.outcarImgIdArr.concat(getPath)})
你这写的啥哦。。。莫名其妙的。。
isnum 每次进来都是0
能做个代码片段吗?