How to open a popup list using API content rendering in Vue
P粉212971745
2023-08-28 19:21:43
<p>I'm trying to open a popup in a rendered list with custom content from an API request. </p>
<p>Currently, I have the following code: </p>
<pre class="brush:php;toolbar:false;"><template>
<div class="biblio__all">
<a v-for="i in items" v-bind:key="i.id" class="biblio__item">
<div class="biblio__text">
<h3 class="biblio__title">{{ i.gsx$titre.$t }}</h3>
<p class="biblio__author">{{ i.gsx$auteur.$t }}</p>
</div>
</a>
<div class="hidden">Put the content of the pop-up window here</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
data () {
return{
items: [],
}
},
created(){
this.axios.get("///API URL")
.then(response => (this.items = response.data.feed.entry))
},
methods: {
}
})
</script></pre>
<p>I want to have another hidden div inside the v-for and when I click on the link, the popup appears. </p>
<p>I have all the data for the popup in the items array. </p>
You can create a separate component for each item and handle its modal state in that component. You can use bootstrap, bulma or pure html and css to make modal boxes. Use
v-show="modalState"
to hide or show the modal box. DefinemodalState
in your child component:Your final structure: