Browse Source

修复storejs的token存储过期时间不生效bug

Rysinal 3 years ago
parent
commit
4f3e45898f
1 changed files with 3 additions and 1 deletions
  1. 3 1
      src/store/modules/user.js

+ 3 - 1
src/store/modules/user.js

@@ -1,8 +1,10 @@
 import storage from 'store'
+import expirePlugin from 'store/plugins/expire'
 import { login, getInfo, logout } from '@/api/login'
 import { ACCESS_TOKEN } from '@/store/mutation-types'
 import { welcome } from '@/utils/util'
 
+storage.addPlugin(expirePlugin)
 const user = {
   state: {
     token: '',
@@ -38,7 +40,7 @@ const user = {
       return new Promise((resolve, reject) => {
         login(userInfo).then(response => {
           const result = response.result
-          storage.set(ACCESS_TOKEN, result.token, 7 * 24 * 60 * 60 * 1000)
+          storage.set(ACCESS_TOKEN, result.token, new Date().getTime() + 7 * 24 * 60 * 60 * 1000)
           commit('SET_TOKEN', result.token)
           resolve()
         }).catch(error => {