Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
Vue CLI: Project list with component

I'm completely new to VueJS and am trying to create a project tile list with different data values per tile. I use Vue CLI. I created a component which is my template for one project tile.

component TheProjectTile.vue :

<template>
  <router-link to="{{ project.url }}">
    <div
      class="row project-container"
      style="background-color: {{ project.backgroundcolor }};"
      v-scrollanimation
    >
      <div class="column column-60">
        <h2>{{ project.title }}</h2>
        <div class="button">view</div>
      </div>
      <div class="column">
        <img src="@/assets/img/{{ project.image }}" alt="{{ project.title }}" />
      </div>
    </div>
  </router-link>
</template>

<script type="text/javascript">
export default {
  props: { project: Object },
  data() {
    return {}
  }
}
</script>

Then I have my View on my Vue CLI application where I want to render the project tiles and where I want to give the data to the tiles:

View where the projects should be shown

<template>
  <div id="projekte">
    <section class="container">
      <div id="projects">
        <projectlist v-for="project in projects" :project="project" />
      </div>
    </section>
  </div>
</template>

<script>
import TheProjectTile from './components/TheProjectTile'

export default {
  components: {
    projectlist: TheProjectTile
  },
  data() {
    return {
      projects: [
        {
          url: '/projekte/client1',
          backgroundcolor: '#005ca9',
          title: 'Website client 1',
          img: 'client1.png'
        },
        {
          url: '/projekte/client2',
          backgroundcolor: '#c10b25',
          title: 'Website client 2',
          img: 'client2.png'
        }
      ]
    }
  }
}
</script>

What do I need to change that it works? :/

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Please take a look at following snippet:

You need to bind data with v-bind or :, in v-for loop you need key

Vue.component('projectList', {
  template: `
    <a :to="project.url">
    <div
      class="row project-container"
      :style="{'background-color': project.backgroundcolor}"
    >
      <div class="column column-60">
        <h2>{{ project.title }}</h2>
        <div class="button">view</div>
      </div>
      <div class="column">                    
        <img :src="'@/assets/img/'+project.image" :alt="project.title" />
      </div>
    </div>
  </a>
  `,
  props: { project: Object },
})

new Vue({
  el: '#demo',
  data() {
    return {
      projects: [{url: '/projekte/client1', backgroundcolor: '#005ca9', title: 'Website client 1', img: 'client1.png'}, {url: '/projekte/client2', backgroundcolor: '#c10b25', title: 'Website client 2', img: 'client2.png'}]
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <div id="projekte">
    <section class="container">
      <div id="projects">
                                                       <!-- 👇 key -->
        <project-list v-for="(project, index) in projects" :key="index" :project="project" />
      </div>
    </section>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda