【问题标题】:Cannot use 'in' operator to search for 'X' in undefined无法使用“in”运算符在未定义中搜索“X”
【发布时间】: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 回复中有错误,但我不知道如何解决。

【问题讨论】:

标签: vue.js vuejs2 vue-component vuetify.js vuex


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-20
    • 2021-11-03
    • 2015-10-12
    • 1970-01-01
    • 2022-01-18
    • 2020-04-08
    • 1970-01-01
    • 2016-03-03
    相关资源
    最近更新 更多