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

130
Visualizações
api call using userid

I need to make an api call to get recommendations for a user. This is my api url: http://URL/../../patients/USER ID/recommendations

My user Id is saved in my vuex store in the file "patient.module.js:

state: {
    id: null,
    email: null,
    password: null,
    location: [],
    specialty: [],
    attribute: [],
    language: [],
    gender: [],
    editUser: false,
  },
  getters: {
    getUserId(state) {
      return state.id;
    },
  },

My store structure looks like this: enter image description here

In my RecommendationView I try to display the json-response from my api call. Here I wrote the method to make the api call.

     methods: {
    getRecommendations() {
      this.id = this.$store.getters.getUserId;
      return http
        .get(`/patients/${id}/recommendations`)
        .then((response) => {
          this.recommendation = response.data;
          console.log(response);
        })
        .catch((error) => {
          console.log(
            "Ein Fehler beim User ist aufgetreten: " + error.response
          );
        });
    },
  },

Unfortunately, I receive this error: id' is not defined How can I get the patient id from the store and send it with my request? Thank you in advance!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can use mapState in computed like this.

<script>
  import {mapState} from "vuex";


export default {
  computed: {
    ...mapState({
      user: state => state.patient
    })
  },
  data() {},
  methods: {
    getRecommendations() {
      this.id = this.user.id;
      return http
        .get(`/patients/${id}/recommendations`)
        .then((response) => {
          this.recommendation = response.data;
          console.log(response);
        })
        .catch((error) => {
          console.log(
            "Ein Fehler beim User ist aufgetreten: " + error.response
          );
        });
    },
  }
} 
</script>

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