How to open a popup list using API content rendering in Vue
P粉212971745
P粉212971745 2023-08-28 19:21:43
0
1
484
<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>
P粉212971745
P粉212971745

reply all(1)
P粉063039990

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. Define modalState in your child component:

data() {
    return {
        modalState: false
    }
}

Your final structure:

<div class="biblio__all">
      <a v-for="i in items" v-bind:key="i.id" class="biblio__item">
          <!-- 拥有模态框和主要项目代码的组件 -->
          <subitem :item="i" />
      </a>

  </div>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template