首页 > 其他 > 详细

VUE:v-for获取列表前n个数据、中间范围数据、末尾n条数据的方法

时间:2019-12-05 14:00:29      阅读:64      评论:0      收藏:0      [点我收藏+]

说明:

  1.开发使用的UI是mintUI,

要求:

1.获取6到13之间的数据:items.slice(6,13)

<mt-cell v-for="(item,index) in items.slice(6,13)" :title="item.title" :key=‘index‘>
    <a :href="item.url" :title="item.title" class="list-url">
         <img :src="item.src" :alt="item.title" class="list-img"/>
    </a>
</mt-cell>

2.获取小于0到6之间的数据:(两种)

  a:items.slice(0,6)

<mt-cell v-for="(item,index) in items.slice(0,6)" :title="item.title" :key=‘index‘>
       <a :href="item.url" :title="item.title" class="list-url">
           <img :src="item.src" :alt="item.title" class="list-img"/>
       </a>
</mt-cell>

  b:v-if="index < 6"

<mt-cell v-for="(item,index) in items" v-if="index < 6" :title="item.title" :key=‘index‘>
       <a :href="item.url" :title="item.title" class="list-url">
           <img :src="item.src" :alt="item.title" class="list-img"/>
       </a>
</mt-cell>

3.获取最后6条数据:items.slice(items.length-6,items.length)

<mt-cell v-for="(item,index) in items.slice(items.length-6,items.length)" :title="item.title" :key=‘index‘>
       <a :href="item.url" :title="item.title" class="list-url">
           <img :src="item.src" :alt="item.title" class="list-img"/>
       </a>
</mt-cell>

 

VUE:v-for获取列表前n个数据、中间范围数据、末尾n条数据的方法

原文:https://www.cnblogs.com/chig/p/11988378.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!