小程序判断图片是否损坏

公共组件errImgae.JS

function errImage(e){
  let idx = e.currentTarget.dataset.idx;
  let type = e.currentTarget.dataset.type;
  let keyNmae = e.currentTarget.dataset.keynmae;
  let img = '';
  type == 'swiper' ? img = '/img/details_02.png' : img = '/img/logo180.png';
  let imgObject = `${type}[${idx}].${keyNmae}`;//修改data数组里面某项需要修改的数据
  return {
    [imgObject]: img
  }
  
}
module.exports = errImage;

在需要的页面中引入改方法
当图片出错时触发 binderror=“errImage”

<view class="course" 
  wx:for="{{course}}" 
  wx:key='index'
  data-catId='{{item.catId}}'
   data-name='{{item.catName}}'
  bindtap="subject"
>
<!--需要把当前数组,和图片字段一起存起来-->
  <image class="course-img" 
    src="{{item.images}}"
    mode="aspectFill"
    data-type='course'
    data-idx='{{index}}'
    data-keyNmae='images'
    binderror="errImage"
   >
   </image>
  <view class="course-text row-ellipsis">{{item.catName}}</view>
</view>
import errImageUrl from '../../../utils/errImgae.js';
//直接引用,当图片出现损坏是就会触发该方法
errImage(e){
    this.setData(errImageUrl(e))
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值