mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +00:00
Fix store module vs store
This commit is contained in:
parent
e95c0a6573
commit
01de17b827
@ -13,9 +13,12 @@ let storeData = {}
|
||||
// Check if store/index.js exists
|
||||
const indexFilename = filenames.find((filename) => filename.includes('./index.'))
|
||||
if (indexFilename) {
|
||||
storeData = getModule(indexFilename)
|
||||
storeData = getModule(indexFilename, true)
|
||||
}
|
||||
|
||||
// If store is not an exported method = modules store
|
||||
if (typeof storeData !== 'function') {
|
||||
|
||||
// Store modules
|
||||
if (!storeData.modules) {
|
||||
storeData.modules = {}
|
||||
@ -33,20 +36,22 @@ for (let filename of filenames) {
|
||||
module[name].namespaced = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// createStore
|
||||
export const createStore = storeData instanceof Function ? storeData : () => {
|
||||
return new Vuex.Store(Object.assign({}, storeData, {
|
||||
state: storeData.state instanceof Function ? storeData.state() : {}
|
||||
// state: storeData.state instanceof Function ? storeData.state() : {}
|
||||
}))
|
||||
}
|
||||
|
||||
// Dynamically require module
|
||||
function getModule (filename) {
|
||||
function getModule (filename, root) {
|
||||
const file = files(filename)
|
||||
const module = file.default || file
|
||||
if (module.state && typeof module.state !== 'function') {
|
||||
throw new Error('[nuxt] store state should be a function.')
|
||||
}
|
||||
// if (root && module.state && typeof module.state !== 'function') {
|
||||
// throw new Error('[nuxt] root store state should be a function.')
|
||||
// }
|
||||
if (module.commit) {
|
||||
throw new Error('[nuxt] store should export raw store options instead of an instance.')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user