Vue.js JSON Stringify


We can use native JavaScript JSON stringify() method to convert json object to json string. Here in this tutorial, we are going to explain how you can use this method to convert an json object to json string in JavaScript in vuejs. You can also use our online editor to edit and run the code online.


Vue.js JSON stringify – JavaScript Example

You can use stringify() method in vuejs simply as below-

Example:

<div id="app">
	<p>{{myStr}}</p>
	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
el: '#app',
  
  data: { 
	  myObj:{"firstName":"John", "lastName":"Doe"},
	  myStr:''
  },
  
   methods:{
    myFunction: function () {	
		this.myStr = JSON.stringify(this.myObj);
    }
   }

});
</script>   

Try it »

Output of above example-


Advertisements

Add Comment

📖 Read More