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

126
Views
Loop v-for through components taken from data

I would like to use v-for to render list of components from the list I have in data.

This is my code

<template>
    <ticket-panel/>
    <user-panel/>
    <map-panel/>
    <info-panel/>
    <product-panel/>
</template>

I want to do something like this

<template v-for="component in components" :key="name">
??? <component> ???
</template>


data: function() {
return {
components: [
    { name: "ticket-panel" },
    { name: "user-panel" },
    { name: "map-panel" },
    { name: "info-panel" },
    { name: "product-panel" }
]
}
}

How to write <template> or <componentName> so it renders properly? I used Google a lot but I did not find any close answer.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can try like following snippet, with special attribute :is

const app = Vue.createApp({
  data() {
    return {
      components: [{name: "ticket-panel"}, {name: "user-panel"}, {name: "map-panel"}, {name: "info-panel"}, {name: "product-panel"}]
    };
  },
})
app.component('ticket-panel', {
  template: `<div>ticket-panel</div>`
})
app.component('user-panel', {
  template: `<div>user-panel</div>`
})
app.component('map-panel', {
  template: `<div>map-panel</div>`
})
app.component('info-panel', {
  template: `<div>info-panel</div>`
})
app.component('product-panel', {
  template: `<div>product-panel</div>`
})
app.mount('#demo')
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
  <div v-for="component in components" :key="component.name">
    <component :is="component.name"></component> 
  </div>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

You can try this process, hopefully, it will work for you. Here is an example for you:

var example1 = new Vue({
  el: '#example-1',
  data: {
    items: [
      { message: 'Foo' },
      { message: 'Bar' }
    ]
  }
})
<ul id="example-1">
  <li v-for="item in items" :key="item.message">
    {{ item.message }}
  </li>
</ul>

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!