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

    Store returns undefined when accessed outside of Component

    Framework
    2
    2
    267
    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.
    • Z
      zerofix last edited by zerofix

      Dear Communitty

      I am in the process of writing my business logic in plain JS files, and would like to access my store to retrieve data stored in the current state. However, I am unable to access the state and am returned a “TypeError: Cannot read property ‘chartOfAccounts’ of undefined”. It thus appears as though it is not the “store” that is undefined, but rather the ‘lumpsum’ module of my store. My question is therefore: How can I access the data from Vuex in my business logic outside of a component?

      My folder structure is the following:

      └── store
          └── lumpsum
                └── state.js
                 ...
       
      

      This is the plain JS File:

      import store from '../store/lumpsum/index'
      
      let classifier = function () {
        // Import Data from Store
        let chartOfAccounts = store.state.lumpsum.chartOfAccounts
        console.log(chartOfAccounts)
      }
      
      export {
        classifier
      }
      
      

      In my component I am then importing this function, and have a method which calls this function.

      import { classifier } from 'src/utils/Classification'
      
      export default {
          methods: {
              classify: function () {
                  classifier()
      } 
          }
      }
      

      My ‘store/lumpsum/state.js’ :

      export default function () {
        return {
          // Raw Data
          chartOfAccounts: []
      }
      

      Could anyone spot the issue which I am missing?

      Thank you in advance

      1 Reply Last reply Reply Quote 0
      • C
        Christal last edited by

        @zerofix Did you find any solution to this issue?

        1 Reply Last reply Reply Quote 0
        • First post
          Last post