Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda