[solved] Why is vuex defined as a function in nuxt?

Business background

  • Learning nuxt static vue Project
  • migrate a completed vue project to the nuxt framework

Perplexities encountered

  • in vue , the definition vuex is an instance object defined directly

the code is as follows:

export default new Vuex.Store({
  state: {
  },
  mutations: {
  },
  debug: true
});
  • but in the nuxt official document, it is defined in this way

sample code is as follows:

const createStore = () => {
  return new Vuex.Store({
    state: {
    },
    mutations: {
    }
  })
}

question

  • nuxt what is the reason for doing this? Instantiate objects only when called to save performance?
  • if I want to call the store object on another non-component page, don"t I have to re-instantiate it again?
Jul.14,2021

when your vuex needs some Synchronize rendered data, the function can accept context objects

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea8db9-47ccd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea8db9-47ccd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?