4

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
5
  • Can you post content of response.data? Commented Dec 20, 2019 at 5:24
  • Yes. Give me a Second. 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 become 'object Object' - i.,e ignore the second console.log, it is completely as expected, the data is correct - use console.log('some string', [someObject, someObject, etc]) ... notice the , instead of the + ... and your console.log will be what you expected in the first place Commented Dec 20, 2019 at 5:25
  • @PrabhjotSinghKainth - the content is completely and utterly irrelevant Commented Dec 20, 2019 at 5:27
  • may you use JSON.stringify() Commented Dec 20, 2019 at 6:11

2 Answers 2

6

"+" operator converting as string in second console statement. Please change it to "," as below?

console.log("Response From VUE JS", this.data);
Sign up to request clarification or add additional context in comments.

Comments

1

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))

2 Comments

JSON.stringify still returns [Object object]
If this is a webapi response, you can view structure in Network tab of the browser to inspect response structure or just console.log(response.data)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.