[store] fix

This commit is contained in:
Pooya Parsa 2017-05-13 22:15:42 +04:30
parent a1d94f4148
commit 05725d70e7

View File

@ -13,7 +13,6 @@ let storeData = {}
// Check if store/index.js exists // Check if store/index.js exists
if (filenames.indexOf('./index.js') !== -1) { if (filenames.indexOf('./index.js') !== -1) {
storeData = getModule('./index.js') storeData = getModule('./index.js')
storeData.state = storeData.state() // Vuex Bug!
} }
// Store modules // Store modules
@ -34,12 +33,16 @@ for (let filename of filenames) {
} }
// createStore // createStore
export const createStore = storeData === 'function' ? storeData : () => new Vuex.Store(storeData) export const createStore = storeData === 'function' ? storeData : () => {
return new Vuex.Store(Object.assign({}, storeData, {
state: storeData.state() // Vuex Bug!
}))
}
// Dynamically require module // Dynamically require module
function getModule (filename) { function getModule (filename) {
const file = files(filename) const file = files(filename)
const module = Object.assign({}, file.default || file) const module = file.default || file
if (module.state && typeof module.state !== 'function') { if (module.state && typeof module.state !== 'function') {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error('[nuxt] store state should be a function.') console.error('[nuxt] store state should be a function.')