小程序-swiper-item点击事件

index.wxml

  <swiper class="banner"  catchtap="onItemClick">
    <block wx:for="{{dataList}}">
      <swiper-item>
        <image src="{{item.img}}" class="slide-image"  data-postId="{{item.id}}" />
      swiper-item>
    block>
  swiper>

index.js

  /**
   * 页面的初始数据
   */
  data: {

    dataList:[
      { id: 1, img:"http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg"},
      { id: 2, img: "http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg" },
      { id: 3, img: "http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg" },
    ]

  },

  onItemClick:function(event){
      wx.showToast({
        title: event.target.dataset.postid+"",
      })
  },

你可能感兴趣的:(小程序)