Reputation: 2613
I query data from a third party API using Vue.js + Axios. The data is returned nicely however it has a bit of confusing structure (nested array).
Somehow the Vue doesn't properly work and I don't see any data renderedat the frontend.
Important to note:
The Vue adds exactly 20 html divs to the frontend after I run the code (which matchs the number of containing elements, but it doesn't display the according data(see images below)).
What might be an issue here?
Javascript part:
var app = new Vue({
el: '#app_name',
data: {
info: []
},
mounted() {
axios
.get("https://cors-anywhere.herokuapp.com/https://www.api-football.com/demo/api/v2/leagueTable/" + league_id)
.then(response => {
this.info = response.data.api.standings[0];
console.log(response.data.api.standings[0]);
});
}
HTML part:
<div class="table" id="app_name">
<div><p>Team</p></div>
<div v-for="Rank in info">
<p>{{ Rank }}</p>
</div>
This is the JSON return, note the nested array:
{
"api": {
"results": 1,
"standings": [
[
{
"rank": 1,
"team_id": 85,
"teamName": "Paris Saint Germain",
"logo": "https://media.api-football.com/teams/85.png",
"group": "Ligue 1",
"forme": "DLWLL",
"description": "Promotion - Champions League (Group Stage)",
"all": {
"matchsPlayed": 35,
"win": 27,
"draw": 4,
"lose": 4,
"goalsFor": 98,
"goalsAgainst": 31
},
"home": {
"matchsPlayed": 18,
"win": 16,
"draw": 2,
"lose": 0,
"goalsFor": 59,
"goalsAgainst": 10
},
"away": {
"matchsPlayed": 17,
"win": 11,
"draw": 2,
"lose": 4,
"goalsFor": 39,
"goalsAgainst": 21
},
"goalsDiff": 67,
"points": 85,
"lastUpdate": "2019-05-04"
},
{...}
]
]
}
}
Before Javascript is executed:
After Javascript is executed:
UPDATE
I tried it with this modification (source: https://github.com/axios/axios/issues/738) but still I don't have any data rendered
var app = new Vue({
el: '#app_name',
data: {
info: []
},
mounted() {
axios.interceptors.request.use(config => {
config.paramsSerializer = params => {
// Qs is already included in the Axios package
return Qs.stringify(params, {
arrayFormat: "brackets",
encode: false
});
};
return config;
});
axios
.get("https://cors-anywhere.herokuapp.com/https://www.api-football.com/demo/api/v2/leagueTable/" + league_id)
.then(response => {
this.info = response.data.api.standings;
console.log(response.data.api.standings);
});
}
Upvotes: 0
Views: 800
Reputation: 1012
This is what you api gives. I think, because of a demo version.
There are no items to display. So Vue not displays anything. It's a problem with the server, not your code.
I'm worried, but maybe you need another api :(
Upvotes: 0
Reputation: 1712
<div v-for="Rank in info">
<p>{{ Rank }}</p>
Here Rank is an object, if you mean to use the rank key you need to
<p>{{ Rank.rank }}</p>
Upvotes: 1