changes
This commit is contained in:
65
.nuxt/store.js
Normal file
65
.nuxt/store.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
let store = {};
|
||||
|
||||
(function updateModules () {
|
||||
store = normalizeRoot(require('../store/index.js'), 'store/index.js')
|
||||
|
||||
// If store is an exported method = classic mode (deprecated)
|
||||
|
||||
if (typeof store === 'function') {
|
||||
return console.warn('Classic mode for store/ is deprecated and will be removed in Nuxt 3.')
|
||||
}
|
||||
|
||||
// Enforce store modules
|
||||
store.modules = store.modules || {}
|
||||
|
||||
// If the environment supports hot reloading...
|
||||
|
||||
if (process.client && module.hot) {
|
||||
// Whenever any Vuex module is updated...
|
||||
module.hot.accept([
|
||||
'../store/index.js',
|
||||
], () => {
|
||||
// Update `root.modules` with the latest definitions.
|
||||
updateModules()
|
||||
// Trigger a hot update in the store.
|
||||
window.$nuxt.$store.hotUpdate(store)
|
||||
})
|
||||
}
|
||||
})()
|
||||
|
||||
// createStore
|
||||
export const createStore = store instanceof Function ? store : () => {
|
||||
return new Vuex.Store(Object.assign({
|
||||
strict: (process.env.NODE_ENV !== 'production')
|
||||
}, store))
|
||||
}
|
||||
|
||||
function normalizeRoot (moduleData, filePath) {
|
||||
moduleData = moduleData.default || moduleData
|
||||
|
||||
if (moduleData.commit) {
|
||||
throw new Error(`[nuxt] ${filePath} should export a method that returns a Vuex instance.`)
|
||||
}
|
||||
|
||||
if (typeof moduleData !== 'function') {
|
||||
// Avoid TypeError: setting a property that has only a getter when overwriting top level keys
|
||||
moduleData = Object.assign({}, moduleData)
|
||||
}
|
||||
return normalizeModule(moduleData, filePath)
|
||||
}
|
||||
|
||||
function normalizeModule (moduleData, filePath) {
|
||||
if (moduleData.state && typeof moduleData.state !== 'function') {
|
||||
console.warn(`'state' should be a method that returns an object in ${filePath}`)
|
||||
|
||||
const state = Object.assign({}, moduleData.state)
|
||||
// Avoid TypeError: setting a property that has only a getter when overwriting top level keys
|
||||
moduleData = Object.assign({}, moduleData, { state: () => state })
|
||||
}
|
||||
return moduleData
|
||||
}
|
||||
Reference in New Issue
Block a user