I'm doing a SPA with Vuejs, (router and axios) I'm trying to get an id of a json object called from an API, for when I click on this feature, that is, I have my APi of https://adventuretimeapi.herokuapp.com/places
adventure time and I want when I click to know residents I get info from the residents but when I'm trying to get it I said undefined
What can I do, I've gone around the code and my brain does not know which is the best way, that's why I come here.
This is my code I'm trying with the Pokemon api that has simpler id
<template>
<router-view v-bind:people="PeopleMain" the-title="Where do you wanna go">
</router-view>
</template>
<script>
import personDisplay from './person-display.vue';
export default {
name: 'app',
data() {
return {PeopleMain: []};
},
components: {
'person-display' : personDisplay
},
created: function() {
var vm = this;
axios.get('http://pokeapi.co/api/v2/pokemon/')
.then(function(response){
vm.PeopleMain = response.data.results;
console.log(response.data.results);
// for (var i=0; i<response.data.length; i++ )
// {
// console.log(vm.PeopleMain[i].residents)
// }
for(var i = 0; i<response.data.length; i++) {
vm.PeopleMain[i].newPlacesId = vm.PeopleMain[i].species.url;
}
})
}
}
</script>
<style lang="scss">
</style>
The router link
<p><router-link :to="'/type/${person.newPlacesId}'">
City Info
</router-link></p>
And where the information will be displayed
<template>
<div>
<h1>Detail</h1>
<p>Name: {{resident.name}}</p>
<p>Fullname: {{resident.fullname}}</p>
</div>
</template>
<script>
import PersonDiplayPlace from './person-display-place.vue';
import PersonDiplay from './person-display.vue';
export default {
name: 'resident',
data() {
return {resident: {}}
},
created() {
var vm = this;
var id = this.$route.params.id;
axios.get('https://pokeapi.co/api/v2/type/${id}/?format=json')
.then(function(response){
vm.resident = response.data
console.log(response.data)
})
}
}
</script>
<style lang="scss">
</style>
I would appreciate if someone could give me a guide, thank you very much for the attention