Answer the question
In order to leave comments, you need to log in
How to properly pass data to an action in Vue?
Guys, hello everyone!
Please help , I
have this function:
getCategories (cb) {
setTimeout(() => cb(
Vue.http.get('category')
.then(response => response.json())
.then(data => {
if (data) {
console.log(data);
const categories = data;
}
})
), 100)
},
const actions = {
getAllCategories ({ commit }) {
shop.getCategories ((categories) => {
commit(types.RECEIVE_CATEGORIES, { categories })
})
}
}
Answer the question
In order to leave comments, you need to log in
Try to rewrite it like this (syntax errors are possible):
getCategories (cb) {
setTimeout(() => {
Vue.http.get('category')
.then(response => response.json())
.then(data => {
if (data) {
console.log(data);
cb(data)
}
}
}), 100)
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question