小程序默认图片设置

//默认图片路径
globleData.definedImageHostUrl;

单个图片

<image src='{{object.image}}' binderror="imageError"></image>
   //对象默认图片设置
   imageError:function(e){
    var object = this.data.object;
    object.image = globleData.definedImageHostUrl;
     this.setData({
       object: object
     })
   },

列表图片

 <image src='{{item.image}}' binderror="imageErrorList" data-index="{{index}}"></image>
//列表默认图设置
   imageErrorList: function (e) {
     var index = e.currentTarget.dataset.index;
     var list= this.data.list;//列表从data内获取
    list[index].image = globleData.definedImageHostUrl;
     this.setData({
       list: list
     })
   },

 for嵌套列表

 <image src='{{item2.image}}' binderror="imageErrorList" data-index="{{index}}  data-index2="{{index2}}"></image>

  

//列表默认图设置
   imageErrorList: function (e) {
     var index = e.currentTarget.dataset.index;
    var index2 = e.currentTarget.dataset.index2;
     var list= this.data.list;//列表从data内获取
    list[index].list2[index2].image = globleData.definedImageHostUrl;
     this.setData({
       list: list
     })
   },

  

posted @ 2019-10-31 16:42  9102  阅读(1269)  评论(0编辑  收藏  举报