Vue嵌套v-for,获取父级的索引

Kap*_*emo 6 vue.js vuex vuejs2

我有一个嵌套的v-for,基本上,我想获取父级的索引v-for并在子级中使用它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>
Run Code Online (Sandbox Code Playgroud)

我尝试使用$parent.$index但仍然不起作用。它没有显示任何错误,但也没有数据。我应该怎么做才能获得index我父母的 v-for?

Ner*_*min 5

只需使用另一个名称定义另一个索引,或者将第一个索引命名为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>
Run Code Online (Sandbox Code Playgroud)