我需要进行 API 调用来为用户获取推荐。这是我的 API 网址: http://URL/../../患者/用户 ID/recommendations
我的用户 ID 保存在我的 vuex 存储中的文件“patent.module.js:
state: {
id: null,
email: null,
password: null,
location: [],
specialty: [],
attribute: [],
language: [],
gender: [],
editUser: false,
},
getters: {
getUserId(state) {
return state.id;
},
},
我的商店结构如下所示:
在我的RecommendationView 中,我尝试显示来自我的api 调用的json 响应。 这里我写了调用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
);
});
},
},
不幸的是,我收到此错误:id' 未定义 我如何从商店获取患者 ID 并将其与我的请求一起发送? 预先感谢您!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您可以像这样使用
mapState进行计算。