diff --git a/src/api/index.ts b/src/api/index.ts
new file mode 100644
index 00000000..5308512a
--- /dev/null
+++ b/src/api/index.ts
@@ -0,0 +1,34 @@
+import router from '@/router'
+import axios from 'axios'
+
+
+// 创建axios实例
+const api = axios.create({
+ baseURL: 'http://localhost:3001/api/v1',
+})
+
+// 添加请求拦截器
+api.interceptors.request.use(config => {
+ const token = localStorage.getItem('token')
+
+ // 在请求头中添加token
+ if (token) {
+ config.headers['Authorization'] = `Bearer ${token}`
+ }
+
+ return config
+})
+
+// 添加响应拦截器
+api.interceptors.response.use(response => {
+ return response.data
+}, error => {
+ if (error.response.status === 403) {
+ // token验证失败,跳转到登录页面
+ router.push('/login')
+ }
+
+ return Promise.reject(error)
+})
+
+export default api
diff --git a/src/pages/login.vue b/src/pages/login.vue
index 7fc35401..daf997ed 100644
--- a/src/pages/login.vue
+++ b/src/pages/login.vue
@@ -1,7 +1,9 @@
@@ -54,14 +96,15 @@ const isPasswordVisible = ref(false)
- {}">
+
-
+
@@ -73,6 +116,7 @@ const isPasswordVisible = ref(false)
:type="isPasswordVisible ? 'text' : 'password'"
:append-inner-icon="isPasswordVisible ? 'mdi-eye-off-outline' : 'mdi-eye-outline'"
@click:append-inner="isPasswordVisible = !isPasswordVisible"
+ required
/>
@@ -80,6 +124,7 @@ const isPasswordVisible = ref(false)
@@ -87,7 +132,6 @@ const isPasswordVisible = ref(false)
登录