Skip to content

Commit

Permalink
fix(store): add namespaced in numFactoryModule
Browse files Browse the repository at this point in the history
  • Loading branch information
XPoet committed Apr 20, 2021
1 parent 4be3279 commit 05b7df5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHashHistory, Router, RouteRecordRaw } from 'vue-router'
import Home from '@/views/Home.vue'
import Vuex from '@/views/Vuex.vue'
import Test from '@/views/Test.vue'
Expand Down Expand Up @@ -26,7 +26,7 @@ const routes: Array<RouteRecordRaw> = [
}
]

const router = createRouter({
const router: Router = createRouter({
history: createWebHashHistory(),
routes
})
Expand Down
23 changes: 8 additions & 15 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
/*
* @Author: Aliom
* @Date: 2021-04-20 10:12:12
* @LastEditors: Aliom
* @LastEditTime: 2021-04-20 10:18:39
*/
import { InjectionKey } from "vue";
import { createStore, Store, useStore as baseUseStore } from 'vuex';
import RootStateTypes, { AllStateTypes } from './interface';
import { InjectionKey } from 'vue'
import { createStore, Store, useStore as baseUseStore } from 'vuex'
import RootStateTypes, { AllStateTypes } from './types'

import numFactoryModule from "./modules/NumFactory";
import numFactoryModule from './modules/NumFactory'

export const store = createStore<RootStateTypes>({
state: {
text: "vuex全局根目录",
text: 'This is Vuex Root.state.text'
},
getters: {},
mutations: {
},
mutations: {},
actions: {},
modules: {
numFactoryModule
}
});
})

export const key: InjectionKey<Store<RootStateTypes>> = Symbol('vue-store');
export const key: InjectionKey<Store<RootStateTypes>> = Symbol('vue-store')

export function useStore<T = AllStateTypes>() {
return baseUseStore<T>(key)
Expand Down
25 changes: 9 additions & 16 deletions src/store/modules/NumFactory/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
/*
* @Author: Aliom
* @Date: 2021-04-20 10:03:47
* @LastEditors: Aliom
* @LastEditTime: 2021-04-20 10:28:54
*/
import { Module } from "vuex";
import NumFactoryStareTypes from './interface';
import RootStateTypes from '../../interface';

import { Module } from 'vuex'
import NumFactoryStateTypes from './types'
import RootStateTypes from '../../types'

// Create a new store Modules.
const numFactoryModule: Module<NumFactoryStareTypes, RootStateTypes> = {
const numFactoryModule: Module<NumFactoryStateTypes, RootStateTypes> = {
namespaced: true,
state: {
name: 'numFactory-module',
count: 1
},
mutations: {
DOUBLE_COUNT(state) {
state.count = 2 * state.count;
DOUBLE_COUNT(state: NumFactoryStateTypes) {
state.count *= 2
}
},
actions: {
},
actions: {}
}

export default numFactoryModule;
export default numFactoryModule
2 changes: 1 addition & 1 deletion src/store/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NumFactoryStateTypes from '../store/modules/NumFactory/interface'
import NumFactoryStateTypes from './modules/NumFactory/types'

export default interface RootStareTypes {
text: string
Expand Down
6 changes: 0 additions & 6 deletions src/views/Vuex.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<!--
* @Author: Aliom
* @Date: 2021-04-20 10:03:47
* @LastEditors: Aliom
* @LastEditTime: 2021-04-20 10:30:28
-->
<template>
<div class="vuex-container page-container">
<div class="page-title">Vuex Test Page</div>
Expand Down

0 comments on commit 05b7df5

Please sign in to comment.