Answer the question
In order to leave comments, you need to log in
Why does nothing come to state?
Hello! Can't figure it out... Here is the code
export const state = () => ({
places: []
})
export const mutations = {
SET_PLACES_TO_STATE: (state, payload) => {
state.places = payload;
},
}
export const actions = {
GETPLACES({ commit }) {
let promise = new Promise(resolve => {
let getPlaces = this.$fireDb.ref()
const receivedPlacesArray = []
getPlaces.on(
'value',
(snapshot) => {
const receivedPlaces = snapshot.val()
receivedPlaces.forEach((el) => {
let item = {
id: el.id,
status: el.status,
}
receivedPlacesArray.push(item)
})
resolve(receivedPlacesArray)
},
(error) => {
console.log('Error: ' + error.code)
}
)
})
promise.then(receivedPlacesArray =>{
console.log(receivedPlacesArray)
commit('SET_PLACES_TO_STATE', receivedPlacesArray);
})
}
}
export const getters = {
GET_PLACES_FROM_STATE(state) {
return state.places
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question