Vue.js get hash from URL


We can use location hash property to get the hash(#) part from url. Here in this tutorial, we are going to explain how you can get the hash(#) from url in Vue.js. You can also use our online editor to edit and run the code online.


Vue.js get hash from URL JavaScript Example

If you want to get the hash from url, you can use the below syntax-

Example:

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

Output of above example-

Vue.js get hash from URL Example

Advertisements

Add Comment

📖 Read More