Skip to content

Commit a913a06

Browse files
author
白唯
committed
feat(vuex & test): 完善 vuex 使用以及更改了组件测试页面
1 parent 2fbba24 commit a913a06

File tree

4 files changed

+46
-51
lines changed

4 files changed

+46
-51
lines changed

src/main.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import { createApp } from 'vue'
2-
import App from '@/App.vue'
3-
import router from '@/router'
4-
import store from '@/store'
5-
import { AppConfig } from '@/config/app'
6-
7-
import { loadAllPlugins } from '@/plugins'
8-
import { registeGlobalComponent } from '@/components/index'
9-
10-
/** 导入第三方插件 */
11-
import '@/plugins'
12-
13-
/** 将全局静态配置注入到应用中,可以通过 this.a读取,比 provide 和 inject 手动注入更方便 */
14-
const app: ReturnType<typeof createApp> = createApp(App)
15-
app.config.globalProperties = AppConfig
16-
17-
/** 加载所有 Plugins */
18-
loadAllPlugins(app)
19-
20-
/** 自动注册全局组件 */
21-
registeGlobalComponent(app)
22-
23-
app
24-
.use(store)
25-
.use(router)
26-
.mount('#app')
1+
import { createApp } from 'vue'
2+
import App from '@/App.vue'
3+
import router from '@/router'
4+
import store from '@/store'
5+
import { AppConfig } from '@/config/app'
6+
7+
import { loadAllPlugins } from '@/plugins'
8+
import { registeGlobalComponent } from '@/components/index'
9+
10+
/** 导入第三方插件 */
11+
import '@/plugins'
12+
13+
/** 将全局静态配置注入到应用中,可以通过 this.a读取,比 provide 和 inject 手动注入更方便 */
14+
const app: ReturnType<typeof createApp> = createApp(App)
15+
app.config.globalProperties = AppConfig
16+
17+
/** 加载所有 Plugins */
18+
loadAllPlugins(app)
19+
20+
/** 自动注册全局组件 */
21+
registeGlobalComponent(app)
22+
23+
app
24+
.use(store)
25+
.use(router)
26+
.mount('#app')

src/store/index.ts

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import { createStore, createLogger, Store } from 'vuex'
22
import createPersistedState from 'vuex-persistedstate'
33
import mutations from './mutations'
44
import modules from './modules'
5-
import { AppStateType } from '@/store/modules/app/state'
65
import { StateType } from '@types'
76

8-
export type GlobalState = { app: AppStateType }
9-
107
const store: Store<StateType> = createStore({
118
strict: true,
129
mutations,
@@ -27,6 +24,4 @@ const store: Store<StateType> = createStore({
2724
]
2825
})
2926

30-
store.state.app?.language
31-
3227
export default store

src/store/modules/app/state.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GlobalState } from '@/store'
1+
import { StateType } from '@types'
22
import { Module } from 'vuex'
33

44
const state = {
@@ -10,7 +10,7 @@ const state = {
1010
}
1111
type AppStateType = typeof state
1212

13-
const app: Module<AppStateType, GlobalState> = { namespaced: true, state }
13+
const app: Module<AppStateType, StateType> = { namespaced: true, state }
1414

1515
export { AppStateType, state }
1616
export default app

src/store/modules/index.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
// https://vuex.vuejs.org/en/modules.html
2-
3-
const files = require.context('.', true, /\.ts$/)
4-
const modules: any = {}
5-
6-
files.keys().forEach((key) => {
7-
if (key === './index.ts') return
8-
const path = key.replace(/(\.\/|\.ts)/g, '')
9-
const [namespace, imported] = path.split('/')
10-
if (!modules[namespace]) {
11-
modules[namespace] = {
12-
namespaced: true
13-
}
14-
}
15-
modules[namespace][imported] = files(key).default
16-
})
17-
18-
export default modules
1+
// https://vuex.vuejs.org/en/modules.html
2+
3+
const files = require.context('.', true, /\.ts$/)
4+
const modules: any = {}
5+
6+
files.keys().forEach(key => {
7+
if (key === './index.ts') return
8+
const path = key.replace(/(\.\/|\.ts)/g, '')
9+
const [namespace, imported] = path.split('/')
10+
if (!modules[namespace]) {
11+
modules[namespace] = {
12+
namespaced: true
13+
}
14+
}
15+
modules[namespace][imported] = files(key).default
16+
})
17+
18+
export default modules

0 commit comments

Comments
 (0)