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

441
Visualizações
Get parameter from URL in Vue JS

I am working on SPA (Vue JS) and Laravel as API. I want when users will receive email to click on button that will sent them to specific route (already implemented).

So now i am struggling how to get the user id from the Vue JS part.

https://domain.test/admin/users/dashboard/user/65/show

65 from the URL is the user ID, so any idea how to extract that ID with java script from Vue JS?

I am not using vue router, this is Laravel route and Vue JS component is rendered from blade file.

I have implemented something like this bellow, but client refused...

https://domain.test/admin/users/dashboard/user/show?userId=65
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

let id = window.location.href.split('/').slice(-2)[0]
about 4 years ago · Juan Pablo Isaza Relatório

0

Since you're already rendering the page in a Blade file, you should already have access to the user ID server side.

In that case, simply add the variable server side. For example:

<a :href="'https://domain.test/admin/users/dashboard/user/' + {{ 
$user->id }} + '/show'">Go to Dashboard</a>
about 4 years ago · Juan Pablo Isaza Relatório

0

To get parmeters from url you can use vue router for that like this:

const routes = [
    // dynamic segments start with a colon
    { path: '/users/:id', component: User },
  ]

const User = {
  template: '<div>User {{ $route.params.id }}</div>',
}

Here is the link for more examples and vue router documentation:

https://router.vuejs.org/guide/essentials/dynamic-matching.html

You can also get parameters with only vanilla JavaScripe like follow:

const queryString = window.location.search;
console.log(queryString);
// ?product=shirt&color=blue&newuser&size=m

//then you have to parse the url
const urlParams = new URLSearchParams(queryString);

const color = urlParams.get('color')
console.log(color);
// blue
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