Answer the question
In order to leave comments, you need to log in
How to synchronously draw a v-for inside a modal window?
I am learning Laravel + VUE. It is not possible to synchronously display the cycle inside the modal window. There is a noticeable jump at opening. If you turn on slow mode, a small empty modal window appears first, then it expands when the v-for list is rendered.
How I do it:
Button to open a modal window (the button itself is in a v-for loop)
<button type="button" class="btn btn-primary btn-sm mt-2" @click="modalOpen(product.id)">Списки</button>
modalOpen(id) {
this.product_id = id,
this.active = true,
}
<modal-list v-if="active"
:product_id="product_id"
:active="active"
>
</modal-list>
props: [
'product_id',
'active'
],
<transition name="modal" v-show="this.active">
mounted() {
this.fetchDataLists();
}
fetchDataLists() {
product_id=this.product_id
axios.get(`/json/datalist/${product_id}`)
.then(response => {
this.datalists = response.data.data;
})
},
<template v-for="(list, index) in datalists" v-model="datalists">
Answer the question
In order to leave comments, you need to log in
As a result, during the discussion, solutions were found:
1) The activ property, which is used to open the modal, is transmitted along with data from the server. This way the modal will not appear before the list is rendered and they will be rendered synchronously. The disadvantage of this bike is the delay in the appearance of the modal until the data arrives.
2) Transfer the already formed data array from the parent. And if you need to change the props, then make a request to the parent via this.$emit and already in the parent change the necessary data in the array via vue.set
3) Hide data loading behind the modal animation.
I settled on the second option. Thanks to Sergey delphinpro and Evgeny Kulakov for ideas
Obviously, there are at least two options:
1. pass a ready-made list so that rendering occurs immediately with the data already available
2. take the data in the component, but do not show it until it is received. Those. inside the modal on the root element put v-show="active" eg active = true - when you got the data.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question