javascript - How to start a v-for loop at a specific index -


how start v-for loop @ specific index.

example: array given array = [a,b,c,d,e,f];

i want use v-for loop start looping 3rd element. thank :)

just use standard slice method:

new vue({    el: '#app',    data: {      items: [        'aaa',        'bbb',        'ccc',        'ddd',        'eee',        'fff'      ]    }  })
<script src="https://unpkg.com/vue@2.4.2/dist/vue.min.js"></script>    <div id="app">    <ul>      <li v-for="item in items.slice(2)">{{ item }}</li>    </ul>  </div>

ps: or v-for v-if:

new vue({    el: '#app',    data: {      items: [        'aaa',        'bbb',        'ccc',        'ddd',        'eee',        'fff'      ]    }  })
<script src="https://unpkg.com/vue@2.4.2/dist/vue.min.js"></script>    <div id="app">    <ul>      <li v-for="(item, index) in items" v-if="index >= 2">{{ item }}</li>    </ul>  </div>

or custom function:

new vue({    el: '#app',    data: {      items: [        'aaa',        'bbb',        'ccc',        'ddd',        'eee',        'fff'      ]    },    methods: {      startfrom (arr, idx) {        return arr.slice(idx)      }    }  })
<script src="https://unpkg.com/vue@2.4.2/dist/vue.min.js"></script>        <div id="app">    <ul>      <li v-for="item in startfrom(items, 2)">{{ item }}</li>    </ul>  </div>


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -