小程序图片绑定错误处理

html 图片加载失败可以 添加onerror绑定默认图片

onerror="this.src='images/loseImg.png'" 

小程序不支持需要自己写方法

// 绑定错误图片
  binderrorimg:function(e){
    var self=this;
    var index = e.currentTarget.dataset.index;   
      let item = 'listGoods[' + index +'].SpPicExtend';
      self.setData({
        [item]: '/images/loseImg.png'
      }) 
  },

页面上

 <image wx:if='{{value.SpPicExtend == ""}}' src='/images/loseImg.png'></image>
<image wx:else src='{{value.SpPicExtend}}' data-type='2' data-index='{{index}}' binderror="binderrorimg"></image>

 

posted @ 2018-09-14 15:52  花影疏帘  阅读(1009)  评论(0)    收藏  举报