Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

466
Views
How to acess url GET parameter in setup() Vue 3?

This is my URL: http://localhost:8888/static/?foo=true via which Vue 3 application works.

In setup() I want to get foo parameter.

This is my code:

import { useRoute } from 'vue-router';
import { defineComponent, reactive, ref, Ref, watch, createApp, onMounted} from 'vue';

export default defineComponent({
  name: 'App',
  
  setup() {
    onMounted(() => {
        const route = useRoute();
        console.log(route);
        console.log(route.params.foo);
        console.log(route.query.foo);
    });
  },
})

And this is what I get: enter image description here

Could anyone say how to do it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think that the root problem is triggering it inside the onMounted hook of the App.vue component. The route instance is probably not yet populated in that moment. You can test it by console.log-ing the route.query inside onUpdated hook. A workaround for you could be something like this:

const unwatch = watch(
  () => route.query,
  (newQuery) => {
    console.log(newQuery.foo);
    unwatch();
  }
);

Basically you would assign a watcher for the route.query and after the first update - the watcher would be destroyed.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!