css

image方法加载失败以后,会调用binderror方法,在wxml中先判断路径是否为空,为空加载默认图片,不为空加载路径图片,如果出错,处理出错方法,换成默认图片

errorFunction: function (e) { var index = e.currentTarget.dataset.index; this.setData({ [`hospitals[${index}].CoverUrl`]: "../../../images/appointment/hospital.png", }) },

<view wx:for="{{hospitals}}" wx:key="Id"> <view class="hospital-container" data-hospcode="{{item.Name}}" data-image="{{item.CoverUrl}}" bindtap="hospitalItemClick"> <image class="hospital-image" src="{{item.CoverUrl==''?'../../../images/appointment/hospital.png':item.CoverUrl}}" data-index="{{index}}"mode="scaleToFill" binderror="errorFunction"></image>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容