get params from route vuejs

In Vue.js, you can retrieve query parameters from the route using the $route.query object. Here are the steps to get the params from the route:

  1. First, make sure you have the Vue Router installed and set up in your project. The Vue Router allows you to define routes and navigate between different pages in your Vue application.

  2. In your component, you can access the route object by importing it from the Vue Router package and assigning it to a local variable. For example:

import { useRouter } from 'vue-router'

export default {
  setup() {
    const router = useRouter()

    // Rest of the component code
  }
}
  1. Once you have access to the $route object, you can access the query parameters using the $route.query object. This object contains key-value pairs for each parameter in the URL query string.

  2. To access a specific parameter, you can use dot notation or square bracket notation on the $route.query object. For example, if your URL is http://example.com?param1=value1&param2=value2, you can access the values of param1 and param2 like this:

const param1 = $route.query.param1
const param2 = $route.query['param2']
  1. You can use these parameter values in your component logic as needed. For example, you can display them in the template or use them to make API requests.

That's it! You have successfully retrieved query parameters from the route in Vue.js using the $route.query object. Remember to import the Vue Router and set it up correctly in your project for this to work.