close

How can I get query parameters from a URL in Vue.js?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How can I get query parameters from a URL in Vue.js? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How can I get query parameters from a URL in Vue.js ?

  1. How can I get query parameters from a URL in Vue.js ?

    can I get query parameters from a URL in Vue.js According to the docs of route object, you have access to a $route object from your components, which exposes what you need. In this case
    //from your component console.log(this.$route.query.test) // outputs 'yay'

  2. How can I get query parameters from a URL in Vue.js ?

    can I get query parameters from a URL in Vue.js According to the docs of route object, you have access to a $route object from your components, which exposes what you need. In this case
    //from your component console.log(this.$route.query.test) // outputs 'yay'

Method 1

According to the docs of route object, you have access to a $route object from your components, which exposes what you need. In this case

//from your component
console.log(this.$route.query.test) // outputs 'yay'

Method 2

Try this code

 var vm = new Vue({
     created()
     {
       let urlParams = new URLSearchParams(window.location.search);
           console.log(urlParams.has('yourParam')); // true
           console.log(urlParams.get('yourParam')); // "MyParam"
     },

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment