小程序之圖片加載失敗問題


1.單個圖片加載失敗,用默認圖片代替

<image src='{{cleanerpicLogo}}' bindload="imageLoad" binderror="imageOnloadError" class='cleanimgs'></image>
// 加載成功
  imageLoad: function (e) {
    console.log("imageLoad"+JSON.stringify(e))
  },
  // 圖片加載失敗
  imageOnloadError(){
    console.log("加載圖片失敗");
    this.setData({
      cleanerpicLogo:'/assets/images/cleanimgs.png'
    })
  },

2,列表圖片加載失敗,用默認圖片代替

<image src="{{item.serviceProduct.headImgUrl}}" data-index="{{index}}" mode='widthFix' class='tabsimg' binderror="imageOnloadError"></image>
imageOnloadError(e) {
    console.log(e);
    var index = e.currentTarget.dataset.index;
    var serviceInfo = this.data.serviceInfo
    serviceInfo[index].serviceProduct.headImgUrl = '/assets/images/productdetailimg.png';
    this.setData({
      serviceInfo: serviceInfo
    })
  },

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM