我得到 \*\* Uncaught (in promise) TypeError: Cannot use ‘in’ operator to search for ‘validateStatus’ in 5f8425a33a14f026f80133ed** 其中 5f8425a33a14f026f80133ed 是传递给 axios url 的 id
我想根据用户 ID 显示服务。我的网址在邮递员中完美运行,但是当我从 veux 商店访问它时,它给出了一个错误。
services.js(商店)
import axios from 'axios';
const state = {
services : {},
status: '',
error: null
};
const getters = {
services : state => { return state.services }
};
const actions = {
async fetchServices({commit}, userId) {
let res = await axios.get('http://localhost:5000/api/services/displayUser' , userId)
commit('setProducts', res.data)
return res;
}
};
const mutations = {
setProducts (state, items) {
state.services= items
},
};
export default {
state,
actions,
mutations,
getters
};
这就是我调用动作的方式:
computed: {
...mapGetters(["services"]),
},
methods: {
...mapActions(["fetchServices"]),
getData(){
this.fetchServices(this.user._id)
},
},
async created() {
await this.getProfile();
await this.getData();
}
axios 路由定义为
router.get('/displayUser', (req,res) => {
const query = user = req.body ;
Services.find(query)
.exec((err, services) => res.json(services))
})
错误截图:
原文由 Jayashree K 发布,翻译遵循 CC BY-SA 4.0 许可协议
GET 请求不应该有正文。使用查询参数,在路径中指定一个 id,或者使用 POST 请求。在查询参数的情况下,这可能看起来像这样: