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

127
Vistas
Vue (2.6.14) - v-for not displaying data with an api import (axios)

The idea I'm trying to build a display where activities are shown with some filters. The data comes from an API generated by the CMS. The filters are not shown in the code since its not relevant.

Problem When manually defining the 'items' in the data property the v-for list rendering displays fine and gives the desired output. When pulling the data from the api and assigning them to items the v-for is not displaying anything.

My Thoughts I think that the v-for is run before the api request is finished putting the data into the 'items' value. Currently I'm using 'created' property to fire the function, also used 'Mounted()' before, this also didn't work.

Versions Vue 2.6.14, Axios 0.21.1

Vue Code

var vue = new Vue({
    el: '#app',
    data: {
        items: null,
    },
    created: function () {
        this.fetchData()
    },
    methods: {
        fetchData: function() {
        axios
            .get('/api/activities.json')
            .then(response => (this.items = response.data.data))
        }
    }
})

Templating

<div id="app">
    <ul class="example">
        <li v-for="item in items">
            {{ item }}
        </li>
    </ul>
</div>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code seems to be working just fine. Look below, I just replaced your api call with a dummy REST api call and it's working just fine. Please console out the data from response.data.data and see if you are really receiving an array there.

Vue.config.productionTip = false
Vue.config.devtools = false


let vue = new Vue({
    el: '#app',
    data: {
        items: null,
    },
    created() {
        this.fetchData()
    },
    methods: {
        fetchData: function() {
        axios.get('https://jsonplaceholder.typicode.com/users')
        .then(response => {  this.items = response.data })}
    }
})
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  <div id="app">
    <ul class="example">
      <li v-for="item in items">
        {{ item.id }} - {{ item.name }}
      </li>
    </ul>
  </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