From 41cba750b5faf3725e06bf2a972cf5d48f099980 Mon Sep 17 00:00:00 2001 From: zc <> Date: Sat, 25 Dec 2021 13:26:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9vuex=E4=B8=BApinia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改vuex为pinia --- README.md | 68 ++++++++----- package.json | 2 +- src/layout/components/AppMain.vue | 8 +- src/layout/components/Navbar.vue | 16 +-- src/layout/components/Settings/index.vue | 20 ++-- src/layout/components/Sidebar/index.vue | 13 +-- src/layout/components/TagsView/index.vue | 28 ++--- src/layout/index.vue | 38 ++++--- src/main.ts | 6 +- src/store/index.ts | 6 -- src/store/modules/app.ts | 35 ++----- src/store/modules/permission.ts | 7 +- src/store/modules/settings.ts | 8 +- src/store/modules/tagsView.ts | 124 +++++++++-------------- src/store/modules/user.ts | 28 +---- src/utils/request.ts | 7 +- src/views/login/index.vue | 4 +- 17 files changed, 179 insertions(+), 239 deletions(-) diff --git a/README.md b/README.md index 04e911f0..5c6318d9 100644 --- a/README.md +++ b/README.md @@ -67,44 +67,60 @@ export default router - [路由的 hash 模式和 history 模式的区别](https://www.cnblogs.com/GGbondLearn/p/12239651.html) -## vuex +## pinia ```shell -npm install vuex@next +npm install pinia ``` -src 下创建 store/interface.ts +src 下创建 store/index.ts ```typescript -import {InjectionKey} from 'vue' -import {createStore, Store} from 'vuex' +import { createPinia } from "pinia"; +const store = createPinia(); +export { store }; +``` +## main.ts -export interface State { - count: number +```typescript +import {createApp} from 'vue' +import App from './App.vue' +import router from "./router"; +import '@/styles/index.scss' +import { store } from "./store"; +import ElementPlus from 'element-plus' +import 'element-plus/theme-chalk/index.css' +import locale from 'element-plus/lib/locale/lang/zh-cn' +import 'virtual:svg-icons-register'; + + +// @see https://blog.csdn.net/qq_37213281/article/details/121422027 +import * as ElIconModules from '@element-plus/icons' +import '@/permission' + + +import Pagination from '@/components/Pagination/index.vue' +import {getDictItemsByCode} from '@/api/system/dict' + + +const app = createApp(App) + +// 统一注册el-icon图标 +// @link https://blog.csdn.net/Alloom/article/details/119415984 +for (let iconName in ElIconModules) { + app.component(iconName, (ElIconModules as any)[iconName]) } -export const key: InjectionKey> = Symbol() +// 全局方法 +app.config.globalProperties.$getDictItemsByCode = getDictItemsByCode +app.component('Pagination', Pagination) // 全局组件 + .use(store) + .use(router) + .use(ElementPlus, {locale}) + .mount('#app') - -export const store = createStore({ - state() { - return { - count: 0 - } - }, - mutations: { - increment(state: { count: number }) { - state.count++ - } - } -}) ``` -**参考文档:** - -- [Vue3 的 InjectionKey 解决提供者和消费者同步注入值的类型](https://www.jianshu.com/p/7064c5f8f143) - - ## element-plus diff --git a/package.json b/package.json index 98decf67..d73047f4 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "nprogress": "^0.2.0", "path-browserify": "^1.0.1", "path-to-regexp": "^6.2.0", - "pinia": "^2.0.6", + "pinia": "^2.0.9", "screenfull": "^6.0.0", "vue": "^3.2.16", "vue-router": "^4.0.12", diff --git a/src/layout/components/AppMain.vue b/src/layout/components/AppMain.vue index 754be628..e48bc59b 100644 --- a/src/layout/components/AppMain.vue +++ b/src/layout/components/AppMain.vue @@ -13,15 +13,13 @@