Vue.js set hash URL


We can use native javascript location.hash property to hash(#) url. Here in this artical we are going to explain how you can use this property in vue.js. You can also use our online editor to edit and run the code online.


Vue.js set hash URL JavaScript Example

You can set the hash url string in vuejs simply as below-

Example:

<div id="app">
	<p>{{result}}</p>
	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
 el: '#app',
  
  data: {
	  result: ''
  },  
   methods:{
    myFunction: function () {		
	 location.hash = "#myhash";
	 this.result = "Hash = "+location.hash;
    }
   }
});
</script>

The above example will set new hash(#) url.

Output of above example-

Vue.js set hash url string

Advertisements

Add Comment

📖 Read More