小程序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 );//注意這裏的賦值方式...  
  },

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章