vue.js的v-for可以限制循环的次数或遍历的开始和结束位置吗

JavaScript010

vue.js的v-for可以限制循环的次数或遍历的开始和结束位置吗,第1张

for肯定是会遍历到头的,也就是从头遍历到尾,

你可以控制遍历完之后渲染的开始和结束位置,比如

<li v-for="(item,index) in items" v-if="item<=3">{{item}}</li>

使用组件里的bind这个神器

<template

v-for="item

in

myway.list">

<compa

v-if="$index

%

2

==

0"

:data="item"></compa>

<compb

v-else

:data="item"></compb>

</template>

整数(Integer):任意自然数(如1,2,3,4,5)以及它们的负数或0。(整数是表示物体个数的数,0表示有0个物体)整数是人类能够掌握的最基本的数学工具。整数的全体构成整数集,整数集合是一个数环。在整数系中,自然数为0和正整数的统称,称0为零,称-1、-2、-3、…、-n、…

(n为整数)为负整数。正整数、零与负整数构成整数系。

一个给定的整数n可以是负数,非负数,零(n=0)或正数。

把showGallery维护成一个数组就能实现了

<img class="item-img " :src="item.imgUrl" @click="handleGalleryClick(item.id)">

<CommonGallery

    :imgs="item.screenshots"

    v-show="showGallery.includes(item.id)"

    @close="handleGalleryClose(item.id)">

</CommonGallery> data() {

  return {

    showGallery: [],

  }

},

methods: {

  handleGalleryClick(id) {

    this.showGallery.push(id)

  },

  handleGalleryClose(id) {

    const index = this.showGallery.indexOf(id)

    this.showGallery.splice(index, 1)

  },