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

224
Views
How to get the query params for the axios call in Vuejs?

HelloWorld.vue

import axios from "axios";
export const deploymentattribute = ({ serv, id }) =>
  axios.get( api cal here .................
    
  );
<template>
  <div>
    <div v-for="(attribute, index) in attributes" :key="index">
      {{ attribute.att }}
    </div>
  </div>
</template> 

<script>
import { deploymentattribute } from "./deploymentattribute";
export default {
  name: "DeploymentAttributeView",
  data() {
    return {
      attributes: [],
    };
  },
  async mounted() {
    const response = await deploymentattribute({
      servicetype: this.$route.query.ser,
      id: this.$route.query.id,
    });
    this.attributes = response.data;
  },
};
</script>

Issue with the code above, I'm unable to get the query string params dynamically. Getting as undefined

Is there any way to pass them dynamically?

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

0

You should have

import axios from "axios";
export const deploymentattribute = ({ servicetype, id }) =>
  axios.get(
    `http://10.11.12.13:3000/servicedetail/?servicetype=${servicetype}&id=${id}`
  );

and

<template>
  <div>
    <div v-for="(attribute, index) in attributes" :key="index">
      {{ attribute.attribute }}
      {{ attribute.value }}
    </div>
  </div>
</template> 

<script>
import { deploymentattribute } from './deploymentattribute'
export default {
  name: "DeploymentAttributeView",
  data() {
    return {
      attributes: [],
    };
  },
  async mounted() {
    const response = await deploymentattribute({ servicetype: this.$route.query.servicetype, id: this.$route.query.id })
    this.attributes = response.data
  },
};
</script>

Because you don't have the this context by default in a js file.

about 4 years ago · Juan Pablo Isaza Report

0

Get the params id either by:

let urlParams = new URLSearchParams(window.location.search);
const id = urlParams.id;

or

 const id = this.$route.query.id;

Then instead of quotes use template literal to use variable value inside a string:

export const deploymentattribute = ({ servicetype, id }) =>
 

  axios.get(`http://example.com/servicedetail/?servicetype=. {servicetype}&id=${id}`);

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