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

208
Views
Vue.js, ¿Cómo enviar un objeto en un enlace api a través de axios?

Así que tengo GET|HEAD api: api/users/{user} , y llama a la función App\Http\Controllers\Api\UserController@show . Esta función en Laravel es:

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

Cómo enviar una id de variable a mi función. En algún lado encontré esto:

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

Pero no funciona. axios.get('/api/users/1') y me devuelve el usuario con id=1 , por lo que el problema es con este enlace en axios.

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

0

Su código no funciona porque está usando comillas simples. Mientras intenta usar literales de plantilla para interpolar, debe cambiar su código a:

 const helpVar = axios.get(`/api/users/${this.$route.params.id}`).then(response => { this.users = response.data; this.loading = false; });
  • Observe el cambio de '' a ``
about 4 years ago · Juan Pablo Isaza Report

0

Creo que deberías usar ` en lugar de ' para que sea posible pasar {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 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!