gpt4 book ai didi

mongodb - 未捕获( promise )TypeError : Cannot use 'in' operator to search for 'validateStatus' in

转载 作者:行者123 更新时间:2023-12-05 08:22:08 34 4
gpt4 key购买 nike

我得到 ** Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'validateStatus' in 5f8425a33a14f026f80133ed** 其中 5f8425a33a14f026f80133ed 是传递给 axios url 的 id

我想根据用户 ID 显示服务。我的 url 在 postman 中完美运行,但是当我从 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))
})

错误截图:

Error screenshot

最佳答案

GET 请求不应该有正文。使用查询参数,在路径中指定一个 id,或者使用 POST 请求。在查询参数的情况下,这可能看起来像这样:

let res = await axios.get('http://localhost:5000/api/services/displayUser' , { params: { userId })
router.get('/displayUser', (req,res) => {
const query = user = req.query;
Services.find(query)
.exec((err, services) => res.json(services))
})

关于mongodb - 未捕获( promise )TypeError : Cannot use 'in' operator to search for 'validateStatus' in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64755537/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com