Image 组件的建议
发布于 6 年前 作者 chao19 15763 次浏览 来自 问答

Image在加载图片的时候,假如图片错误,或者图片URL不存在,能否提供监听回调,

例如:

<image src=“https://www.xxx.com/pages/images/undefined”/>

这种情况想给image默认图,

H5开发 img标签会提供 onerror事件! 小程序能否支持类似这样的API 。

4 回复

binderror事件怎么使用呢,只能打印出错误信息,具体方案是什么呢?

background-image能满足你的需求吗……

dyzperr:function(e){
  console.log(e);
  var i = e.target.dataset.index
  var imgObject = "dylb[" + i + "].thumb"
  var errorImg = {}
  errorImg[imgObject] = "/wxdy/img/dy.jpg"
  //this.setData(errorImg)
},

可以在事件响应函数中指定图片。可是微信报警了,这样可能会频繁地setData引起性能障碍

实际上如果图片丢失,image组件是透明的。只要预先把默认图片设为image组件的背景图片就可以了

不是有binderror事件吗

回到顶部