收藏
回答

关于长列表swiper-item只显示3个如何优化?

<swiper @change="changevideo">

    

<block v-for='(item, key) in topSwipers' wx:key='key'>
 <swiper-item v-if="(key >= (currentkey - 1)) && (key <= (currentkey + 1))" :style="{position: 'relative', height: '100%'}" :item-id="item.playerid" :data-xid="key">
   <txv-video
     @touchstart="touchStart"
     @touchend="touchEnd"
     width="100%"
     height="100%"
     :vslideGestureInFullscreen="false"
     object-fit="cover"
     id="txtvideo"
     style="margin-top: 10rem !important;width: 100%;height: 100%;"
     :loop="true"
     direction="0"
     :vid="item.vid"
     v-if="item.mode == 1 && item.playerid == ifplay && key == currentkey"
     :playerid="item.playerid"
     :controls="false"
     objectFit="contain"
     :autoplay="item.mode == 1 && item.playerid == ifplay"
     :isHiddenStop="false"
   >
   </txv-video>
   <txv-video
     @touchstart="touchStart"
     @touchend="touchEnd"
     width="100%"
     height="100%"
     :vslideGestureInFullscreen="false"
     object-fit="cover"
     id="txtvideo"
     style="margin-top: 10rem !important;width: 100%;height: 100%;"
     :loop="true"
     direction="0"
     :vid="item.vid"
     v-if="(item.mode == 0 || item.mode == 2) && item.playerid == ifplay && key == currentkey"
     :playerid="item.playerid"
     :controls="false"
     :autoplay="(item.mode == 0 || item.mode == 2) && item.playerid == ifplay"
     :isHiddenStop="false"
   >
   </txv-video>
   <div class="lanmu" v-if="item.playerid == ifplay">
     <img class="avatar-img" :src="item.avatar" />
     <view @click="like(item.playerid, item)" style="height: 150rpx; padding-top: 20rpx;">
       <img class="like-img" :src="liked ? '/static/images/like.png' : '/static/images/love.png'"/>
       <span class="praise-txt">{{item.praise}}</span>
     </view>

     <!--              <img class="send-img" src="../../../static/images/send.png" />-->
     <button class="share-btn" open-type="share" :data-rid="item.message"></button>
     <!--              <span class="praise-txt">{{item.share}}</span>-->
   </div>
   <div class="bottomview" v-if="item.playerid == ifplay">
     <span class="nicktxt">@{{item.nickname}}</span>
     <span class="messagetxt">#{{item.message}}#</span>
   </div>
 </swiper-item>
</block>


</swiper>

没加

v-if="(key >= (currentkey - 1)) && (key <= (currentkey + 1))"

这个条件之前是可以滑动的,加这个的原因就是想要优化一下长列表swiper里面的item,让他每次只显示当前滑动的那一个和上下两个,目前问题是,加了这个条件之后,currentkey对应不上,只有0,1,2了,请问一下这个是什么问题,我应该如何优化这个组件呢?

回答关注问题邀请回答
收藏

3 个回答

  • 
    2019-08-22

    请问你解决了吗?我也遇到这个问题了

    2019-08-22
    有用
    回复 4
    • Lola
      Lola
      2019-08-22
      你是swiper-item过长,不知道如何清理是吗?想要用这个https://www.jianshu.com/p/bf1ae1cb00e6 思路吗?
      2019-08-22
      回复
    • Lola
      Lola
      2019-08-22
      可以对swiper数组下手
      2019-08-22
      回复
    • 
      2019-08-22回复Lola
      我开始就是想到这个了 但是不起作用
      2019-08-22
      回复
    • 
      2019-08-22回复Lola
      我开始以为是swiper里边的节点过多而导致的卡顿,但是我发现我的不是,我的是使用了富文本解析的那个组件才卡的,不用那个就不卡了
      2019-08-22
      回复
  • A notorious liar(小花猫)
    A notorious liar(小花猫)
    2019-08-19

    高度用vh例如:height:100vh


    2019-08-19
    有用
    回复
  • 睡前原谅一切
    睡前原谅一切
    2019-08-19

    麻烦写成代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

    2019-08-19
    有用
    回复 8
    • Lola
      Lola
      2019-08-19
      这边是用mpvue写的,基本语法是vuejs和小程序的结合
      2019-08-19
      回复
    • Lola
      Lola
      2019-08-19
      swiper上下滑动的思路是一样的,不知可否加个QQ探讨一下
      2019-08-19
      回复
    • Lola
      Lola
      2019-08-19
      https://www.jianshu.com/p/bf1ae1cb00e6 优化思路受这篇文的启发
      2019-08-19
      回复
    • 睡前原谅一切
      睡前原谅一切
      2019-08-19回复Lola
      你的实现 是想 每页显示3个内容是吧?
      2019-08-19
      回复
    • Lola
      Lola
      2019-08-19回复睡前原谅一切
      是,滑到当前的,和上下 这三个,v-if="(key >= (currentkey - 1)) && (key <= (currentkey + 1))",但swiper-item加了这个都不行,滑到第三个视频就出不来了
      2019-08-19
      回复
    查看更多(3)
登录 后发表内容
问题标签