Vue Js Get base URL
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:




Thanks for your feedback!
Your contributions will help us to improve service.
Vue Js Get Base Url -javascript property
xxxxxxxxxx
baseUrl :window.location.origin
How to get Base Url in Vue.js?
This code creates a Vue app and displays the current website's base URL using Vue data binding. It uses JavaScript to get the website's origin and sets it to a Vue data property named baseUrl
. The HTML element with the ID of app
is mounted to the Vue app, and the baseUrl
property is displayed using Vue data binding.
Vue Js Get Base Url Example
xxxxxxxxxx
<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>