N
N
Nikolay Semenov2017-06-17 13:05:11
JavaScript
Nikolay Semenov, 2017-06-17 13:05:11

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)
        
    },

it gets categories on request. this is done in a separate file. then exported to
a file with actions
here are the actions itself:
const actions = {
    getAllCategories ({ commit }) {
        shop.getCategories ((categories) => {
            commit(types.RECEIVE_CATEGORIES, { categories })
        })
    }
}

however no data is written to state

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2017-06-17
@nickola105

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 question

Ask a Question

731 491 924 answers to any question