3
I’m trying to pull up a list of names coming from a json (http://pokeapi.co/api/v2/pokemon) using the Xios but I don’t understand why I get the error
Typeerror: Cannot set Property 'Pokemons' of Undefined
Since my.log console is returning the list correctly, it follows the code of my Vue component:
<template>
<div class="w-cards">
<div v-for="pokemon in pokemons" class="card">
<h1>{{pokemon.name}}</h1>
</div>
</div>
<script>
import axios from 'axios'
export default {
data() {
return {
pokemons: {
},
}
},
created: function() {
this.buscaPokemons();
},
methods: {
buscaPokemons: function(){
axios.get('http://pokeapi.co/api/v2/pokemon')
.then(function(res){
console.log(res);
console.log(res.data.results);
this.pokemons = res.data.results;
})
.catch(function(err){
console.log(err);
})
}
},
}
</script>