1.單個圖片加載失敗,用默認圖片代替this
<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,列表圖片加載失敗,用默認圖片代替spa
<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 }) },