html52.com
我爱小程序-开发者交流社区

图片URL用数组的concat拼出来的会显示不出来?

图片存在腾讯云里的,获取图都需要一个个拼接URL,小程序里打印出来数组里有值,但页面image标签的src显示为空。



<block wx:for="{{items}}" wx:key="id">
     <view id='{{index}}' class="view-item" >
           <image src='{{outcarImgIdArr[index]}}' mode="widthFix"></image>
     </view>

</block>



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

能做个代码片段吗?

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付