【发布时间】:2021-02-21 14:27:27
【问题描述】:
我得到 ** Uncaught (in promise) TypeError: Cannot use 'in' operator to search '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))
})
错误截图:
【问题讨论】: