you want to know how to retrieve the data?
Aug 1, 2019
10
Level 1
Axios call on nested JSON api data
Hi guys,
I’m following a tutorial http://blog.vuejoy.com/4-axios/ to make an axios call to a JSON api. The code works fine when I call the source as given in the tutorial. Howevr my JSON data has a nested structure. here is the code to make the call:
created() {
//axios.get('http://jsonplaceholder.typicode.com/posts').then((response) => {
axios.get('http://myexample.com/api/node/page').then((response) => {
this.posts = response.data
})
.catch((e) => {
console.error(e)
})
}
and here is the structure of the data I want to grab:
{
"jsonapi": {
"version": "1.0",
"meta": {
"links": {
"self": {
"href": "http://jsonapi.org/format/1.0/"
}
}
}
},
"data": [
{
"type": "node--page",
"id": "c6bf24a8-8556-4c55-b7eb-cb387dbb36f5",
"attributes": {
"status": true,
"title": "API Test", //// this here
"body": {
"value": "<p>Here is some content</p>\r\n", ///// and this here
"format": "rich_text",
"processed": "<p>Here is some content</p>",
"summary": ""
},
I want to grab the title and the body value, what is the proper format for making the call?
Thanks in advance
Level 3
@ludo1960 use post.title and post.body.value in the vue template. add id like this so you can use it for key binding
this.posts = response.data.data.map((post) => {
return {id: post.id, title: post.attributes.title, body: post.attributes.body};
})
Please or to participate in this conversation.