使用binderror方法綁定錯(cuò)誤事件處理事件
<image src="{{info.background}}" class='agent_bg' mode='aspectFill' binderror='errorFunction'></image>
使用errorFunction方法對圖片進(jìn)行替換
/ 圖片加載失敗處理
? errorFunction: function (e) {
? ? if (e.type == "error") {
? ? ? var background = this.data.info.background //將圖片列表數(shù)據(jù)綁定到變量
? ? ? background= this.data.defaultImgBg //錯(cuò)誤圖片替換為默認(rèn)圖片
? ? ? this.setData({
? ? ? ? ['info.background']: background
? ? ?})
? ? }
? },