I have a nested v-for
, basically, I want to get the index of the parent v-for
and use it inside the child v-for
<template v-for="(branch, index) in $store.state.agency.branch_users.users">
<table class="table" id="agency-contact-table" >
<thead>
<tr>
<th aria-colindex="1" class="">#</th>
<th aria-colindex="1" class="">Name</th>
</tr>
</thead>
<tbody>
<tr v-if="branch.role_users" v-for="(branch_users, index) in branch.role_users">
<td>{{$parent.$index}}</td>
<td>{{branch_users.user.first_name}} {{branch_users.user.last_name}}</td>
</tr>
</tbody>
</table>
</template>
I tried using $parent.$index
but it still doesn't work. It doesn't show any errors but no data also.
What should I do to get the index
in my parent v-for?
Just define the other index with another name, or name the first as parent_index
<template v-for="(branch, parent_index) in $store.state.agency.branch_users.users">
<table class="table" id="agency-contact-table" >
<thead>
<tr>
<th aria-colindex="1" class="">#</th>
<th aria-colindex="1" class="">Name</th>
</tr>
</thead>
<tbody>
<tr v-if="branch.role_users" v-for="(branch_users, index) in branch.role_users">
<td>{{parent_index}}</td>
<td>{{branch_users.user.first_name}} {{branch_users.user.last_name}}</td>
</tr>
</tbody>
</table>
</template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With