Skip first result from v-for vuejs2
use v-for
+ v-if
(see guide)
When they exist on the same node, v-for has a higher priority than v-if. That means the v-if will be run on each iteration of the loop separately. This can be useful when you want to render nodes for only some items, like below:
UPDATED: Added a better approach
example:
new Vue({
el: '#app',
computed: {
filteredArray() {
return this.array.filter(item => !!item.firstName);
},
},
data: {
array: [
{
firstName: '',
lastName: '',
age: 0
},
{
firstName: 'Dirk',
lastName: 'Doe',
age: 41
},
{
firstName: 'Julia',
lastName: 'Doe',
age: 25
}
]
}
})
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<div id="app">
<li v-for="user in filteredArray">
{{ user.firstName }} - age: {{user.age}}
</li>
<pre>old array = {{ array }}</pre>
</div>
What Voldymyr wrote
<li v-for="(value, index) in array" v-if="value.firstName">
{{ value.firstName }} - index: {{index}}
</li>
seems fine to exclude data which has got firstname null or empty. But to avoid the first record (that's what you asked), the best way I can think of is,
<li v-for="(value, index) in array" v-if="index">
{{ value.firstName }} - index: {{index}}
<li>
The index will be 0 for the first record, and v-if(index)
will be false
.
Change
this.arrayresults = [{id:'' ,username: '',useremail: '',userphone:'',}]
to
this.arrayresults = []