张延森 2 years ago
parent
commit
bc4493ffbf
3 changed files with 6 additions and 4 deletions
  1. 1
    1
      src/router/index.js
  2. 4
    3
      src/utils/request.js
  3. 1
    0
      src/utils/token.js

+ 1
- 1
src/router/index.js View File

@@ -33,7 +33,7 @@ router.beforeEach((to, from, next) => {
33 33
     }).catch((err) => {
34 34
       console.error(err)
35 35
       NProgress.done();
36
-      next({ name: 'login', query: { from: encodeURIComponent(from.fullPath) } });
36
+      next({ name: 'login', query: { from: encodeURIComponent(to.fullPath) } });
37 37
     })
38 38
   } else {
39 39
     next();

+ 4
- 3
src/utils/request.js View File

@@ -7,8 +7,9 @@ const request = axios.create({
7 7
 
8 8
 // 添加请求拦截器
9 9
 request.interceptors.request.use(function (config = {}) {
10
-  const { header = {} } = config
10
+  const { headers = {} } = config
11 11
   const token = getToken()
12
+  console.log('-----token----', token)
12 13
   const Authorization = token ? { Authorization: token } : {};
13 14
 
14 15
   // 加载动画
@@ -17,8 +18,8 @@ request.interceptors.request.use(function (config = {}) {
17 18
   // 在发送请求之前做些什么
18 19
   return {
19 20
     ...config,
20
-    header: {
21
-      ...header,
21
+    headers: {
22
+      ...headers,
22 23
       ...Authorization,
23 24
     }
24 25
   };

+ 1
- 0
src/utils/token.js View File

@@ -10,6 +10,7 @@ export function setToken(val) {
10 10
 
11 11
 export function getToken() {
12 12
   const ciphertext = localStorage.getItem(tk)
13
+  console.log('-----ciphertext----', ciphertext)
13 14
   if (ciphertext === null || ciphertext === undefined) return;
14 15
 
15 16
   return CryptoJS.AES.decrypt(ciphertext, se).toString(CryptoJS.enc.Utf8);