Vue.js get location pathname
We can use location pathname property to get the current pathname in Vue.js. Here in this tutorial, we are going to explain how you can get location pathname in Vue.js. You can also use our online editor to edit and run the code online.
Vue.js get location pathname JavaScript Example
You can get the location.pathname 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 () { this.result = location.pathname; } } }); </script> |
Output of above example-
Advertisements