0.1.0 • Published 3 years ago

vue-loop-helper v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

VueLoop

A loop helper plugin inspired by Blade.

Installation

1. Install

yarn add vue-loop-helper
# or
npm i vue-loop-helper --save

2. Plug-in

import VueLoop from 'vue-loop-helper'

Vue.use(VueLoop)

3. Use in your components

<template>
  <div v-for='item in items'>
    {{ $loop.index }}
    {{ $loop.count }}
    {{ $loop.first }}
    {{ $loop.last }}
    {{ item }}
  </div>
</template>

<script>
  export default {
    data () {
      return {
        items: [
          'foo',
          'bar',
          'baz'
        ]
      }
    }
  };
</script>

Helpers

PropertyDescription
$loop.indexThe index of the current loop iteration (starts at 0).
$loop.iterationThe current loop iteration (starts at 1).
$loop.remainingThe iterations remaining in the loop.
$loop.countThe total number of items in the array being iterated.
$loop.firstWhether this is the first iteration through the loop.
$loop.lastWhether this is the last iteration through the loop.
$loop.evenWhether this is an even iteration through the loop.
$loop.oddWhether this is an odd iteration through the loop.
$loop.depthThe nesting level of the current loop.
$loop.parentWhen in a nested loop, the parent's loop variable.

Credits

The implementation of this module is inspired by Laravel (Blade)

License

MIT