参考文章:https://blog.csdn.net/jifashihan/article/details/105809743
wxml:
<view class="room_item" wx:for="{{roomList}}" wx:key="rid">
<!-- 左侧 图片容器 -->
<view class="room_img_wrap">
<image mode="widthFix" src="{{item.imageSrc}}" data-index="{{index}}" binderror="findError"></image>
</view>
</view>
js:
// 图片加载失败
findError: function (e) {
console.log(e)
var index = e.currentTarget.dataset.index; // html中必须有data-index属性
this.setData({
[`roomList[${index}].imgSrc`]: "https://ww1.sinaimg.cn/large/007rAy9hgy1g24by9t530j30i20i2glm.jpg",
// roomList 即 映射数组;imgSrc数组中的key值;其他原样copy即可
})
},