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 //从新赋值 }) }