Gabotronix's avatar

Get vuex action response in component

Hi everybody, I'm trying to get the response object resulting of calling a vuex action with axios, I need the response in my object but it says undefined for some reason.

In my component method:

mounted()
{
    console.log(this.$options.name+' component successfully mounted');
    this.$store.dispatch(this.module+'/'+this.action, this.payload)
    .then((response) => 
    { 
        console.log(response);
        this.items = response.data.data;
        this.pagination = response.data.pagination;

    });
},

My vuex action:

list({ commit }, payload)
    {
        commit( 'Loader/SET_LOADER', { status:1 }, { root: true });
        return axios.get('/api/posts', { params: payload })
        .then((response) => {
            commit('Loader/SET_LOADER', { status:2, response:response }, { root: true });
            console.log(response);
            commit('SET_POSTS',  response.data.data.data );
            commit('SET_PAGINATION',  response.data.pagination );
        })
        .catch((error) => {
            commit('Loader/SET_LOADER', { status:3, errors: error }, { root: true });
            throw error;
        });
    },

Using vuex state is not an option, I want to use the component data properties items and pagination instead.

0 likes
0 replies

Please or to participate in this conversation.