Vue.js Get first and last value of list-item (li)

Today, We want to share with you Vue.js Get first and last value of list-item (li).In this post we will show you How to Conditionally Apply a CSS Class in Vue.js, hear for List Rendering and Vue’s v-for Directive we will give you demo and example for implement.In this post, we will learn about List Item Vue Component Framework7 Vue Documentation with an example.

Vue.js Get first and last value of list-item (li)

There are the Following The simple About Templates, loops and conditions with VueJS Full Information With Example and source code.

As I will cover this Post with live Working example to develop Targeting last item in v-repeat with Vue JS, so the for loop in vue methods is used for this example is following below.

Read Also:  ng-table using Angular Example

Targeting last item in v-repeat with Vue JS

<li v-repeat="products" v-class="last : $index === (products.length-1)">
  <i class="material-icons">{{ icon }}</i>
    {{ name }}
</li>

For Vue 2.0 the source code

<li v-for="(item, index) in products" v-bind:class="{last : index === (products.length-1)}">
  <i class="material-icons">{{ icon }}</i>
    {{ name }}
</li>

Iterating Over Items in Vue.js With V-for

V-for with Objects

data() {
  return {
    objectItems: {
      key1: 'item1',
      key2: 'item 2',
      key3: 'item3'
    }
  }
}
<ul>
  <li v-for="item in objectItems">{{ item }}</li>
</ul>

<ul>
  <li v-for="(item, key, index) in objectItems">
    {{ item }} - {{ key }} - {{ index }}
  </li>
</ul>

V-for with Range

<ul>
  <li v-for="item in 15">{{ item }}</li>
</ul>

//using Key
<ul>
  <li v-for="item in shoppingItems" :key="item.name">
    {{ item.name }} - {{ item.price }}
  </li>
</ul>

Filtering list

Read Also:  Golang to Find the GCD and LCM of Two Integers

Using computed values to filter items

<ul>
  <li v-for="item in itemsLessThanTen" :key="item.name">
    {{ item.name }} - {{ item.price }}
  </li>
</ul>
data() {
  return {
    shoppingItems: [
      {name: 'apple', price: '7'},
      {name: 'orange', price: '12'}
    ]
  }
},
computed:{
  itemsLessThanTen: function() {
    return this.shoppingItems.filter(function(item) {
      return item.price > 10;
    })
  }
}

Using a method to filter items

<ul>
  <li v-for="item in filterItems(shoppingItems)" :key="item.name">
    {{ item.name }} - {{ item.price }}
  </li>
</ul>

data() {
  return {
    shoppingItems: [
      {name: 'apple', price: '7'},
      {name: 'orange', price: '12'}
    ]
  }
},
methods:{
  filterItems: function(products) {
    return products.filter(function(item) {
      return item.price > 10;
    })
  }
}

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about for loop in vue methods.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.