import Vue from 'vue'
import Vuex from 'vuex'
import home from './modules/home'
import cachePlugin from './plugins/cache'
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
home,
editActivity,
editGuide
}
plugins: [cachePlugin]
})
export default store
需求:
cache使用map来实现
因为esm输出的是值的引用,直接就是单例模式了
详细
版本1
注意: 在插件里面获取的mutations-type是包含命名空间的,而在actions里面则是没有命名空间,需要补全。 /mutation-types.js
/modules/home/index.js
/plugin/cache.js
store/index.js
版本2
优化点:
/actions.js
/在fetchOrCache判断是需要缓存,还是请求接口