Vue Js Get Base Url: In Vue.js, you can use the window.location.origin
property to get the base URL of your application. This property returns the protocol, domain name, and port number of the current URL.
window.location
is a property of the global window
object in JavaScript that contains information about the current URL of the page. The origin
property of the location
object returns the protocol, domain name, and port number of the current URL.
In Vue.js, you can access the window
object from any component using the window
global variable. So, to get the base URL of your Vue.js application, you can simply use window.location.origin
like this:
Vue Js Get Base Url -javascript property
baseUrl :window.location.origin
How to get Base Url in Vue.js?
This code creates a Vue
Vue Js Get Base Url Example
<div id="app">
<p>Base Url:{{baseUrl}}</p>
</div>
<script type="module">
const app = Vue.createApp({
data() {
return {
baseUrl :window.location.origin
}
},
});
app.mount('#app');
</script>