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

298
Views
Vue use route params for axios get request

So I'm building my first vue project and I've been trying to pass route parameters to an axios get request and it's not working. this is the code for the page, it gets rendered after the user clicks on a dynamic link in a table of tests

<template>
  <v-app>

    <app-navbar />

    <v-main>
        <h3>test {{$route.params.name}}, {{$route.query.status}},{{$route.query.tag}}</h3>
        <h3>{{items}}</h3>
    </v-main>
  </v-app>
</template>

<script>
import appNavbar from '../../../components/appNavbar.vue';
import axios from "axios";
export default {
  components : {appNavbar},
  name: "App",
  data() {
    return {
      items: [],
    };
  },
  async created() {
    try {
      const res = await axios.get(`http://localhost:3004/tests`,{ params: $route.params.name });
      this.items = res.data;
    } catch (error) {
      console.log(error);
    }
  },
};
</script>

<style lang="scss" scoped>

</style>

how can i pass the route params to the axios get function ?

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

0

This should be this.$route.params.name inside the script.

const res = await axios.get(`http://localhost:3004/tests`,{ params: this.$route.params.name });
about 4 years ago · Juan Pablo Isaza Report

0

Router.js const routes = [ { path: 'path/:name', name: 'Name', component: ComponentName, } ]

about 4 years ago · Juan Pablo Isaza Report

0

I used @Nitheesh solution I just had to specify the parameter name and it worked perfectly Solution:

const res = await axios.get(`http://localhost:3004/tests`,{ params: {name:this.$route.params.name} });
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!