Vue.js get Hostname
Native JavaScript location hostname property to get the hostname. Here in this tutorial, we are going to explain how you can get hostname in vue.js. You can also use our online editor to edit and run the code online.
Vue.js get Hostname Example
You can use location.host to get and set the hostname in vue.js-
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.host; } } }); </script> |
Output of above example-
Advertisements