No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Accessing Vuex Store in Boot files

    CLI
    2
    2
    1178
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      CPHM last edited by

      I want to use vuex in a boot file to read user’s saved access token and info from LocalStorage and commit the data to store and use it in other boot files (for example axios boot file) and vue components. I tried to export Vuex instance from the src/store/index but I get the following error:

      Uncaught ReferenceError: Cannot access 'store' before initialization
      

      Here is my src/store/index:

      import Vue from "vue";
      import Vuex from "vuex";
      
      import auth from "./auth";
      
      let store = null;
      
      Vue.use(Vuex);
      
      export default function (/* { ssrContext } */) {
        const Store = new Vuex.Store({
          modules: {
            auth,
          },
        });
      
        store = Store;
      
        return Store;
      }
      
      export { store };
      

      and I just imported the instance in boot files:

      import { store } from "src/store";
      

      By the way I tried putting a console.log() in the createStore function in store/index and it doesn’t show up.

      beets 1 Reply Last reply Reply Quote 0
      • beets
        beets @CPHM last edited by

        @cphm The boot file default function gets passed the store instance:

        export default async ({ app, router, store, Vue }) => {
         // use store here, no need to import it
        }
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post