From 2242872c5ca07e47513e5ed63a3484ee2976b4aa Mon Sep 17 00:00:00 2001 From: aringlai Date: Fri, 16 Apr 2021 12:51:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20store=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/fes-plugin-vuex/src/index.js | 2 +- packages/fes-plugin-vuex/src/runtime/core.tpl | 14 ++++++++------ packages/fes-template/src/app.js | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/fes-plugin-vuex/src/index.js b/packages/fes-plugin-vuex/src/index.js index d2b69cce..705edab1 100644 --- a/packages/fes-plugin-vuex/src/index.js +++ b/packages/fes-plugin-vuex/src/index.js @@ -54,7 +54,7 @@ export default (api) => { api.addPluginExports(() => [ { - specifiers: ['MUTATION_TYPES', 'ACTION_TYPES', 'GETTER_TYPES'], + specifiers: ['MUTATION_TYPES', 'ACTION_TYPES', 'GETTER_TYPES', 'store'], source: absCoreFilePath } ]); diff --git a/packages/fes-plugin-vuex/src/runtime/core.tpl b/packages/fes-plugin-vuex/src/runtime/core.tpl index 7366fc01..09a05e7f 100644 --- a/packages/fes-plugin-vuex/src/runtime/core.tpl +++ b/packages/fes-plugin-vuex/src/runtime/core.tpl @@ -8,18 +8,20 @@ const ACTION_TYPES = {{{ACTION_TYPES}}}; const GETTER_TYPES = {{{GETTER_TYPES}}}; const conifg = {{{VUEX_CONFIG}}}; +const store = createStore({ + modules: modules, + plugins: {{{PLUGINS}}}, + strict: conifg.strict, + devtools: conifg.devtools +}) const install = function (app) { - app.use(createStore({ - modules: modules, - plugins: {{{PLUGINS}}}, - strict: conifg.strict, - devtools: conifg.devtools - })); + app.use(store); } export { install, + store, MUTATION_TYPES, ACTION_TYPES, GETTER_TYPES diff --git a/packages/fes-template/src/app.js b/packages/fes-template/src/app.js index 5e380442..dfc169a2 100644 --- a/packages/fes-template/src/app.js +++ b/packages/fes-template/src/app.js @@ -1,9 +1,11 @@ -import { access as accessApi } from '@fesjs/fes'; +import { access as accessApi, store, GETTER_TYPES } from '@fesjs/fes'; import PageLoading from '@/components/PageLoading'; import UserCenter from '@/components/UserCenter'; +console.log(store.getters[GETTER_TYPES.user.address]); + export const beforeRender = { loading: , action() { From 8da5057fe6a841dab22d79f5b208be193054e0b5 Mon Sep 17 00:00:00 2001 From: aringlai Date: Fri, 16 Apr 2021 12:52:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20vuex=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/reference/plugin/plugins/vuex.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/reference/plugin/plugins/vuex.md b/docs/reference/plugin/plugins/vuex.md index 9d11c96c..7f962078 100644 --- a/docs/reference/plugin/plugins/vuex.md +++ b/docs/reference/plugin/plugins/vuex.md @@ -49,6 +49,13 @@ store.getters[GETTER_TYPES.user.address] store.commit(MUTATION_TYPES.counter.increment) store.dispatch(ACTION_TYPES.user.login) ``` + +```js +import { MUTATION_TYPES, GETTER_TYPES, ACTION_TYPES, store } from '@fesjs/fes'; +store.getters[GETTER_TYPES.user.address] +store.commit(MUTATION_TYPES.counter.increment) +store.dispatch(ACTION_TYPES.user.login) +``` ## API ### MUTATION_TYPES * 类型 `Object`