小程序binderror的使用方法

 1.场景是在list列表中,有的logo图片会404出错

如果图片出错展示不了,就让它展示,默认图。

<view wx:for="{{list}}" wx:key="{{item}}" wx:for-index="index" wx:for-item="item" 
    data-item="{{item}}" class="house-list" catchtap="_goinDetail">
        <image src="{{ item.logo + '?x-oss-process=style/hd'}}" wx:if="{{item.logo}}"
        class="house-photo" binderror="binderrorimg" data-errorImg="list[{{index}}].logo"/> 
</view>
//list 是你循环的数组,index 就是此标签的下标

js:

  binderrorimg: function (e) {
    console.log(e)
    var errorImg= e.target.dataset.errorImg;    
    var strImg = "'" + _errImg + "'";     
    var errObj = {};
    errObj [errorImg] = "https://***.png";
    // console.log(e.detail.errMsg , errObj [errorImg] , strImg);
    this.setData(errObj );//注意这里的赋值方式...  
  },
发布了149 篇原创文章 · 获赞 51 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/caoyan0829/article/details/92805312