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!
You can use
mapState
for calculations like this.