[Vuejs]-Shopping Cart with Vue and Vuex

0👍

You can use axios to make a call to the server and get products like following

export default new Vuex.Store({
    state: {
        products: {},
    },
    actions: {
        getProducts({commit},data) {
            axios.get(`api/product?page=`+ data.page + '&orderBy='+ data.orderBy).then((response) => {
            commit('updateProducts', response.data);
        })
    },
    mutations: {
        updateProducts (state, products) {
            state.products = products
        }
    }
});

Leave a comment