【发布时间】:2021-04-16 07:40:56
【问题描述】:
Uncaught TypeError: Cannot use 'in' operator to search 'USERS' in undefined 我看不懂这一行:use 'in' operator to search for 'USERS'
还有为什么undefined?
我不明白这些错误请给我解释一下。
我的 Vuex:
export default new Vuex.Store({
state: {
users: []
},
actions: {
GET_USERS_FROM_API({commit}) {
return axios('http://localhost:3000/users', {
method: GET
})
.then((response) => {
commit('SET_USERS_TO_VUEX', response.data)
})
}
},
mutations: {
SET_USERS_TO_VUEX: (state, users) => {
state.users = users
}
},
getters: {
USERS(state) {
return state.users
}
},
modules: {
}
这是我的脚本:
import {mapActions, mapGetters} from 'vuex'
export default {
name: 'Home',
components: {
},
data() {
},
computed: {
...mapGetters([
'USERS'
])
},
methods: {
...mapActions([
'GET_USERS_FROM_API'
])
},
mounted() {
this.GET_USERS_FROM_API()
}
}
</script>
也许我在vuex 中的axios 回复中出错了?我defined用户状态。我想我的axios 回复中有错误,但我不知道如何解决。
【问题讨论】:
-
可能不相关,但
method: GET应该是method: 'GET' -
在我的代码方法'GET'中
-
该错误是指
in运算符,您的帖子中未使用该运算符,因此它可能来自其他地方。 developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
标签: vue.js vuejs2 vue-component vuetify.js vuex