Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!