So I am writing this Vue.JS code to display a data aquired by PHP from a server. The PHP returns a JSON object to the Vue and the VUE has to display it. My current code is:
axiosPost();
}
function axiosPost()
{
axios.post(
'./ConversationGetter.php',
{
function2call: 'getRecord',
id: 1,
access: this.accesstoken
}
)
.then(response => {this.data=response.data;
console.log(response.data);
console.log("Response From VUE JS"+this.data);
})
.catch(error => {});
}
The Problem is, First console.log
prints the Response data properly. But the second console.log
displays the this:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
If I use JSON.parse while displaying the data, it shows this:
undefined
So I am writing this Vue.JS code to display a data aquired by PHP from a server. The PHP returns a JSON object to the Vue and the VUE has to display it. My current code is:
axiosPost();
}
function axiosPost()
{
axios.post(
'./ConversationGetter.php',
{
function2call: 'getRecord',
id: 1,
access: this.accesstoken
}
)
.then(response => {this.data=response.data;
console.log(response.data);
console.log("Response From VUE JS"+this.data);
})
.catch(error => {});
}
The Problem is, First console.log
prints the Response data properly. But the second console.log
displays the this:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
If I use JSON.parse while displaying the data, it shows this:
undefined
Share
Improve this question
edited Dec 20, 2019 at 5:36
Shri
asked Dec 20, 2019 at 5:21
ShriShri
7611 gold badge9 silver badges27 bronze badges
5
- Can you post content of response.data? – Prabhjot Singh Kainth Commented Dec 20, 2019 at 5:24
- Yes. Give me a Second. – Shri Commented Dec 20, 2019 at 5:24
-
because
console.log('some string' + [someObject, someObject, etc])
coerces the array of objects in this.data to be an array of strings, and objects as strings bee'object Object'
- i.,e ignore the second console.log, it is pletely as expected, the data is correct - useconsole.log('some string', [someObject, someObject, etc])
... notice the,
instead of the+
... and your console.log will be what you expected in the first place – Jaromanda X Commented Dec 20, 2019 at 5:25 - @PrabhjotSinghKainth - the content is pletely and utterly irrelevant – Jaromanda X Commented Dec 20, 2019 at 5:27
- may you use JSON.stringify() – Oswald Commented Dec 20, 2019 at 6:11
2 Answers
Reset to default 6"+" operator converting as string in second console statement. Please change it to "," as below?
console.log("Response From VUE JS", this.data);
You do not need JSON.parse
.. Just use response.data
direct. If you want to see actual data use console.log(JSON.stringify(response.data))