Sometimes, we want to show JSON result with Vue.js.
In this article, we’ll look at how to show JSON result with Vue.js.
How to show JSON result with Vue.js?
To show JSON result with Vue.js, we can use the JSON.stringify
method with the pre
element.
For instance, we write
<template>
<div>
<pre>{{ JSON.stringify(yourObject, null, 2) }}</pre>
</div>
</template>
to pretty print the yourObject
JSON object reactive property by calling JSON.stringify
with it and 2 to indent each level by 2 spaces.
And we put the returned JSON string in a pre
element so that all the whitespaces are rendered.
Conclusion
To show JSON result with Vue.js, we can use the JSON.stringify
method with the pre
element.