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 de586a08..d73047f4 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "nprogress": "^0.2.0", "path-browserify": "^1.0.1", "path-to-regexp": "^6.2.0", + "pinia": "^2.0.9", "screenfull": "^6.0.0", "vue": "^3.2.16", "vue-router": "^4.0.12", diff --git a/src/api/system/role.ts b/src/api/system/role.ts index 635b84bf..6962fed8 100644 --- a/src/api/system/role.ts +++ b/src/api/system/role.ts @@ -131,4 +131,4 @@ export function saveRolePerms(roleId: number, menuId: number, permIds: Array import {defineComponent} from "vue"; -import {useStore} from '@/store' import {useRoute} from "vue-router"; - +import {tagsViewStoreHook} from '@/store/modules/tagsView' export default defineComponent({ setup() { - const store = useStore() const route = useRoute() const cachedViews = () => { - return store.state.tagsView.cachedViews + return tagsViewStoreHook().cachedViews } const key = () => { return route.path @@ -68,4 +66,4 @@ export default defineComponent({ padding-right: 15px; } } - \ No newline at end of file + diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index d047b191..26d98b1e 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -48,12 +48,13 @@