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

338
Views
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.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

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 ``
over 4 years ago · Santiago Trujillo Report

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;
             
        });

over 4 years ago · Santiago Trujillo 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!