Programing

Vue 중첩 v-for, 상위 인덱스 가져오기

c10106 2022. 3. 6. 10:49
반응형

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>

나는 사용하려고 노력했다.$parent.$index하지만 여전히 효과가 없어오류는 없지만 데이터도 없다.내가 어떻게 해야 그 물건을 얻을 수 있을까?index내 부모님한테 무슨 일이요?

다른 이름으로 다른 인덱스를 정의하거나 첫 번째 인덱스의 이름을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>

참조URL: https://stackoverflow.com/questions/52902752/vue-nested-v-for-get-index-of-parent

반응형