Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

465
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda