Answer the question
In order to leave comments, you need to log in
Router-view inside v-for loop. How to set a dynamic route name?
I create a component - a directory of contacts. Inside this component, there is a loop that creates separate router-views for each card with its own unique name. This is done so that each card can be edited separately, showing the edit form only in it (contact information disappears -> a form with edit fields appears)
<template>
<div class="contact-cards">
<div class="contact-cards__wrap">
<h4 class="contact-cards__title">Контактные лица</h4>
<router-link :to="'/panel/partners/' + this.$route.params.id + '/add-contact'">
<button class="btn btn-outline-primary button-add">Добавить контакт</button>
</router-link>
</div>
<div class="contact-card contact-cards__contact-card" v-for="contact in contacts" :key="contact.id">
<router-view :name="'info' + contact.id" />
</div>
<router-link :to="'/panel/partners/' + this.$route.params.id + '/add-contact'">
<button class="btn btn-outline-primary button-add">Добавить контакт</button>
</router-link>
</div>
</template>
{
path: '/panel/partners/:id',
component: () => import('./components/partner/partners/profile-partner.vue'),
children: [
{
path: '/panel/partners/:id',
components: {
info: () => import('./components/partner/partners/profile/view-data-for-partner.vue'),
contact: () => import('./components/partner/partners/profile/view-contact-person.vue'),
company: () => import('./components/partner/partners/profile/view-company.vue'),
},
children: [
{
path: '/panel/partners/:id',
components: {
"тут имя с переменной": () => import('./components/partner/partners/profile/contact-person.vue'),
}
}
]
},
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question