Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
Vue.js, How to send object in api link via axios?

So I have GET|HEAD api: api/users/{user}, and it calls function App\Http\Controllers\Api\UserController@show. This function in Laravel is:

   public function show($id){
    return new UserShowResource(User::findOrFail($id));
}

How to send variable id to my function. I found somewhere this:

const helpVar = axios.get('/api/users/{this.$route.params.id}').then(response => {
           this.users = response.data;
           this.loading = false;
             
        });

But it does not work. I tried axios.get('/api/users/1') and it returns me user with id=1, so problem is with this link in axios.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Your code isn't working because your are using simple quotation marks. As you are trying to use template literals for interpolating you must change your code to:


const helpVar = axios.get(`/api/users/${this.$route.params.id}`).then(response => {
           this.users = response.data;
           this.loading = false;
             
        });
  • Notice the change of '' to ``
about 4 years ago · Juan Pablo Isaza Denunciar

0

I think you should use ` instead of ' so its possible to pass {this.$route.params.id} ;


const helpVar = axios.get(`/api/users/{this.$route.params.id}`).then(response => {
           this.users = response.data;
           this.loading = false;
             
        });

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda