Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use 'in' operator to search for 'X' in undefined

Uncaught TypeError: Cannot use 'in' operator to search for 'USERS' in undefined I can't understand this line : use 'in' operator to search for 'USERS' and also why undefined ?

I do not understand these errors please explain to me.

My 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: {

}

Here is my script:

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>

Maybe I misstaked in axios response in my vuex ? I defined users in state. I think i get error in my axios response, but I do not know how to fix it.

like image 202
Justin Moreyl Avatar asked Nov 20 '25 23:11

Justin Moreyl


1 Answers

syntax error, forgot to put quotation marks to the GET method and also forgot to import axios

like image 107
Justin Moreyl Avatar answered Nov 23 '25 04:11

Justin Moreyl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!