收藏
回答

使用mpvue开发小程序,v-for新生成的元素上绑定的事件失效

HTML代码如下:


<view
 
  v-show="!showLoading"
 
  v-for="(item, index) in cards"
 
  :key="index"
 
  class="body-swiper"
 
  @touchstart="touchstart"
 
  @touchend="touchend($event, index, item.content.user.id)"
 
  :style="{'z-index': (10 - index), top: item.top + 'px'}"
 
  :animation="item.animation">
 
    <!-- 不相关的内容 -->
 
</view>

js代码如下:

对ajax接口返回的数据做处理:

for(let i=0;i<res.data.list.length;i++) {
 
  // 有一些不相关的内容
 
  let item = {
 
    content: res.data.list[i],
 
    top: 18,
 
    animation: {}
 
  };
 
  this.cards.push(item);
 
  this.showLoading = false;
 
}

其中res.data.list中的数据是每次返回10条,

在初次进入页面时,请求接口的前10条数据循环生成的卡片上是有touchstarttouchend事件的,

之后的第二个10条中的数据循环生成的卡片元素上的事件就不起作用了


请问应该怎么改?


最后一次编辑于  2019-02-28
回答关注问题邀请回答
收藏

3 个回答

  • 折戟沉沙
    折戟沉沙
    2019-11-30

    你好,请问这个问题解决了吗?

    2019-11-30
    有用
    回复
  • 土豆
    土豆
    2019-02-28

    每次点击重新加载页面数据



    2019-02-28
    有用
    回复 2
    • 师传志
      师传志
      2019-02-28

      您好,没看懂您的答案,能在我提供的代码上改吗?或者再具体讲讲,谢谢

      2019-02-28
      回复
    • 土豆
      土豆
      2019-03-01

      可以看看touchend是什么内容么?有完整点的页面代码么?


      2019-03-01
      回复
  • 疯狂的小辣椒
    疯狂的小辣椒
    2019-02-28

    你好,是 mpvue 的问题,请去 mpvue 的 github ub https://github.com/Meituan-Dianping/mpvue 提  issue。

    2019-02-28
    有用
    回复
登录 后发表内容