How to get current URL in Vue JS
In this post we will give you information about How to get current URL in Vue JS. Hear we will give you detail about How to get current URL in Vue JS And how to use it also give you demo for it if it is necessary.
In this short article, We will learn How to get the current URL in Vue.js.
If you are using Vue without Vue Router then you need to an use window
object. But, If you are using Vue Router then you can use a route object.
Also see: How to Use Props in Vue.js
How to get the current URL in Vue JS without Vue Router
<!DOCTYPE html>
<html>
<head>
<title>How to get current URL in Vue JS - onlinecode</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
{{ message }}
</div>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
message: 'How to get current URL in Vue JS - onlinecode'
},
created: function(){
var currentUrl = window.location.pathname;
console.log('Current URL => ${currentUrl}');
}
})
</script>
</body>
</html>
How to get the current URL in Vue JS with Vue Router
<script>
export default {
created(){
console.log(this.$route.query.page)
}
}
</script>
Thank you for reading How to get current URL in Vue JS blog. Hope this code and post will helped you for implement How to get current URL in Vue JS. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs