Vue.js encode URL


We can use JavaScript Native JavaScript in-built function encodeURIComponent to encode url in vuejs. Here in this tutorial, we are going to explain how you can use this method to encode url. You can also use our online editor to edit and run the code online.


Vue.js encode URL JavaScript Example

You can use encodeURIComponent function in vue.js simply as below –

Example:

<div id="app">
	<p>Result 1 = {{result}}</p>
	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
 el: '#app',
  
  data: {
	  result:'',
	  myUrl:'http://www.example.com/index.html?param=1&param=2'
  },  
   methods:{
    myFunction: function () {
	 this.result = encodeURIComponent(this.myUrl);
    }
   }
});
</script> 

Try it »

Output of above example-

Vue.js encode URL

Advertisements

Add Comment

📖 Read More