小编Kap*_*emo的帖子

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

我有一个嵌套的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?

vue.js vuex vuejs2

6
推荐指数
1
解决办法
3658
查看次数

标签 统计

vue.js ×1

vuejs2 ×1

vuex ×1