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.
syntax error, forgot to put quotation marks to the GET method and also forgot to import axios
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With