How to call a vuex action in component?

Viewed 843

I have created a vuex with some actions and I want to call those actions in component. I tried to map it but in response I am getting 404.

This is my VueX for stockist.js -

import api from '@shiba/src/api';

export default {
    namespaced: true,
    actions: {
        get_store_names: () => {
            return api.get('stockist/get-store-names').then((response) => {
                return response.data;
            });
        },
    },
};

I want to call get_store_names in component called shipping-method using mapState -

import { mapState } from 'vuex';
export default {
    //some code
    computed: {
        ...mapState('stockist'),
    },

    mounted() {
        this.getStores();
    },

    methods: {
        getStores() {
            this.$store.dispatch('stockist/get_store_names').then((response) => {
                console.log(response); //getting 404
            });
        },
    }
}
0 Answers
Related