张延森 2 年之前
父節點
當前提交
bc4493ffbf
共有 3 個文件被更改,包括 6 次插入4 次删除
  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 查看文件

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

+ 4
- 3
src/utils/request.js 查看文件

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

+ 1
- 0
src/utils/token.js 查看文件

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