From f38acbd7a7b8a1a8af6b93f85e1b3d7b7c6eaec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=8C=E7=B3=96=E5=8C=85=E5=AD=90?= Date: Sun, 15 Jan 2023 13:45:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5element-plus=E5=9B=BE?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/main.ts | 16 +++++++++++----- yarn.lock | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index af72f24..b837e83 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "serve": "vite preview" }, "dependencies": { + "@element-plus/icons-vue": "^2.0.10", "aplayer": "^1.10.1", "axios": "^0.22.0", "echarts": "^5.2.1", diff --git a/src/main.ts b/src/main.ts index 00aea57..777bbc3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,11 +11,13 @@ const service = axios.create({ }) import { ElMessage, ElLoading } from 'element-plus' +import * as ElementPlusIconsVue from '@element-plus/icons-vue' + // 添加请求拦截器 service.interceptors.request.use(config => { // 在发送请求之前添加token到请求头 - const token = app.$store.state.loginInfo.token + const token = mountedApp.$store.state.loginInfo.token if (token !== null && config.headers) { config.headers.token = token } @@ -39,7 +41,7 @@ service.interceptors.response.use(res=> { ElMessage.warning(message) } if (err.response.status === 403) { - app.$router.push('/login') + mountedApp.$router.push('/login') } } return Promise.reject(err) @@ -47,8 +49,8 @@ service.interceptors.response.use(res=> { // 全局路由导航前置守卫 router.beforeEach(function (to, from, next) { - app.$store.commit('setBreadcrumb', routePathes[to.path] || []) - if(filterExclude.indexOf(to.path) !== -1 || app.$store.state.loginInfo.token) { + mountedApp.$store.commit('setBreadcrumb', routePathes[to.path] || []) + if(filterExclude.indexOf(to.path) !== -1 || mountedApp.$store.state.loginInfo.token) { next() } else { next('/login') @@ -56,7 +58,11 @@ router.beforeEach(function (to, from, next) { }) const app = createApp(App) - .use(router) +for (const [key, component] of Object.entries(ElementPlusIconsVue)) { + app.component(key, component) +} + +const mountedApp = app.use(router) .use(store) .use(VueAxios, service) .directive('loading', ElLoading.directive) diff --git a/yarn.lock b/yarn.lock index 7c4b91e..d7507d2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -25,7 +25,7 @@ resolved "https://registry.yarnpkg.com/@ctrl/tinycolor/-/tinycolor-3.5.0.tgz#6e52b3d1c38d13130101771821e09cdd414a16bc" integrity sha512-tlJpwF40DEQcfR/QF+wNMVyGMaO9FQp6Z1Wahj4Gk3CJQYHwA2xVG7iKDFdW6zuxZY9XWOpGcfNCTsX4McOsOg== -"@element-plus/icons-vue@^2.0.6": +"@element-plus/icons-vue@^2.0.10", "@element-plus/icons-vue@^2.0.6": version "2.0.10" resolved "https://registry.yarnpkg.com/@element-plus/icons-vue/-/icons-vue-2.0.10.tgz#60808d613c3dbdad025577022be8a972739ade21" integrity sha512-ygEZ1mwPjcPo/OulhzLE7mtDrQBWI8vZzEWSNB2W/RNCRjoQGwbaK4N8lV4rid7Ts4qvySU3njMN7YCiSlSaTQ==