Making API calls using user ID
P粉320361201
P粉320361201 2024-03-27 11:12:31
0
1
338

I need to make an API call to get recommendations for the user. This is my API URL: http://URL/../../patient/userID/recommendations

My user ID is saved in my vuex store in the file "patent.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:

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

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 get this error: id' is not defined How do I get the patient ID from the store and send it with my request? Thank you in advance!

P粉320361201
P粉320361201

reply all(1)
P粉553428780

You can use mapState for calculations like this.

sssccc
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!