9951 explained code solutions for 126 technologies


vue.jsHow do I use Vue.js to get query parameters?


Vue.js provides a simple way to access query parameters in the URL. To do this, you can use the $route object, which is available on all Vue components.

// Get the query parameters
const queryParams = this.$route.query;

The queryParams object will contain all the query parameters in the URL. For example, if the URL is http://example.com?name=John&age=20, the queryParams object will look like this:

{
    name: "John",
    age: 20
}

You can also use the $route object to get the full URL, including the query parameters:

// Get the full URL
const fullUrl = this.$route.fullPath;

// Outputs: http://example.com?name=John&age=20
console.log(fullUrl);

To learn more about the $route object, please refer to the Vue.js documentation.

Edit this code on GitHub