import { createApp } from 'vue' import { createPinia } from 'pinia' // [新增] 引入 Pinia import App from './App.vue' // 1. 引入路由配置 import router from './router' // 2. 引入 Element Plus import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' // 引入中文包 import zhCn from 'element-plus/es/locale/lang/zh-cn' // 3. 引入图标 import * as ElementPlusIconsVue from '@element-plus/icons-vue' // 4. 引入全局样式 (通常建议加上,如果没有可忽略) import './style.css' const app = createApp(App) // ========================================================= // [关键修复] 注册顺序非常重要! // 1. 必须先注册 Pinia,因为 Router 的守卫中会用到 Store // ========================================================= const pinia = createPinia() app.use(pinia) // ========================================================= // 2. 然后注册 Router // ========================================================= app.use(router) // 3. 注册 Element Plus app.use(ElementPlus, { locale: zhCn, // 设置为中文 }) // 4. 注册所有图标 for (const [key, component] of Object.entries(ElementPlusIconsVue)) { app.component(key, component) } app.mount('#app')