search

Home  >  Q&A  >  body text

How to open a popup list using API content rendering in Vue

<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粉212971745P粉212971745462 days ago475

reply all(1)I'll reply

  • P粉063039990

    P粉0630399902023-08-29 12:55:47

    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>

    reply
    0
  • Cancelreply