Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
How can I show different divs dynamically based on an ID received from an API response

This is my first time posting on stackoverflow!

I'm currently in the process of building a sort of social media webapp. I just started on the notifications page of the webapp. My issue is that different notifications have different templates. So while some notifications may include an image, other notifications do not. I've had success displaying a feed by looping through a JSON array with the id as the key, but I don't think I can do that with the notifications pane. Each notification has its separate ID, so looping through them isn't the issue. My main issue is that each notification has its own type attribute, and I want to display different div templates depending on the type, while looping through the JSON using the ID.

For clarification, I'm using the quasar cli for vue.js.

I'll attach my code for the loop below for some context.

Any help would be appreciated. I tried searching for this issue and found nothing, though that maybe an issue of me not knowing how to search properly.

<q-card
       class = "no-padding"
       style = "height: 150px;"
       v-for = "event in joinedEvents"
       :key = "event.id" flat> 

Basically, I want to be able to have the display an image if the notification type is 1 or display button if it is 2.

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can make use of dynamic component feature of vue js, define your notification templates and then based on identifier set them dynamically, by using this method you can use single model for as many templates you want

Template structure will be like this

  • Components
    • Notifications
      • Template A
      • Tempalte B
      • Template C
      • ---- etc.

In vue just model component make use of

<component :is="myDynamicComponent" :data="myDyanmicDataForComponent" />

Whenever you receive notification just set the template and data then make it visible.

Here is a working example:

https://codesandbox.io/s/vue-dynamic-template-example-gwt9d

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda