gpt4 book ai didi

vue.js - 无法使用 'in' 运算符在 undefined 中搜索 'X'

转载 作者:行者123 更新时间:2023-12-05 03:45:39 26 4
gpt4 key购买 nike

Uncaught TypeError: Cannot use 'in' operator to search for '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 响应?我在状态中定义 用户。我想我的 axios 响应出错了,但我不知道如何修复它。

最佳答案

语法错误,忘记给GET方法加上引号,也忘记导入axios

关于vue.js - 无法使用 'in' 运算符在 undefined 中搜索 'X',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65665578/

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