微信小程序,默认图片设置

<image src='{{detailsList.abstractDrawing.url == undefined ? img : detailsList.abstractDrawing.url}}' binderror="errImg" class='img'></image>
<text class='txt1'>[{{detailsList.patentLanguage}}] {{detailsList.application.applicationCode}}</text>
<text class='txt2'>{{detailsList.inventionTitle}}</text>
<view class='recordTop'></view>

  

 
// 默认图片
errImg: function (e) {
  if (e.type == 'error') {
    var imgList = this.data.detailsList; //将图片列表数据绑定到变量
    imgList.abstractDrawing.url = this.data.imgSrc;
    this.setData({
      detailsList: imgList
    })
  }
},

imgSrc为默认的图片路径,

注意:detailsList 是对象格式,里面的abstractDrawing.url要和wxml对应,请看上面wxml里面的image组件

分享这段代码就是看到其他博客里面有人分享的不是很好读懂,而且文档上面写的比较简单,对于新人不能快速使用,所以分享一下,如果有不对的地方,希望大家指出,以免误导他人

  

猜你喜欢

转载自www.cnblogs.com/bufanpeng001/p/9177079.html
今日推荐