[Vuejs]-Access Vue store inside service

0👍

There’s no issue with the code. Probably the importing of the store making the issue. If you’re exporting your store as const, then you can import it like

// your store file
export const store = new Vuex.Store({
    modules: {
      // your modules
    },
});

// importing store to other files
import {store} from "../store/store"

Otherwise you can simply import like

import store from "../store/store"
👤Rijosh

0👍

Your state is unknown because of the following declaration:

import { store } from './store'

Originally, Vue recommends not to use the curly braces, but it prevents you from having state issues.

-1👍

No need to import the entire store. U can pass the necessary variables in the call “leadsOverTime” using context.

State variables cannot be accessed directly in actions, So use context to access the state variables.

Also to commit a mutation u can call like “context.commit”

Correct me If am wrong I am new to vue

const actions = {
  async leadsOverTime( context , group_by = '') {
    const response = await LeadsService.leadsOverTime(group_by,context.state);
    context.commit('leadsOverTime', response)
    return true
  },
};

Leave a comment