onerror屬性的使用方法以下:html
onerror="this.src='XXX.jpg'"
binderror="onImageError"
onImageError: function(e){ var index = e.currentTarget.dataset.index; //獲取咱們在image標籤中傳過來的data-index的數據,以獲取下標 var topList = this.data.topList; //獲取data中接收咱們發出請求得到響應的數據 var errorImageItem = topList[index]; //獲取圖片出錯的對象 errorImageItem.images.large = '../../images/error_img.jpg'; //把路徑修改成咱們的替代圖片 topList[index] = errorImageItem; //把修改完路徑後的對象覆蓋原先的對象 this.setData({ topList: topList //從新賦值 }) }