Browse Source

优化token失效、退出后,为了强制清空整站临时存储数据而刷新页面问题。注意: 此次vux数据并未做重置处理!

daxiongYang 6 years ago
parent
commit
9785ad9344
2 changed files with 4 additions and 6 deletions
  1. 2 3
      src/utils/httpRequest.js
  2. 2 3
      src/views/main-navbar.vue

+ 2 - 3
src/utils/httpRequest.js

28
http.interceptors.response.use(response => {
28
http.interceptors.response.use(response => {
29
  if (response.data && response.data.code === 401) { // 401, token失效
29
  if (response.data && response.data.code === 401) { // 401, token失效
30
    Vue.cookie.delete('token')
30
    Vue.cookie.delete('token')
31
    router.push({ name: 'login' }, () => {
32
      location.reload() // 刷新页面, 清空整站临时存储数据
33
    })
31
    router.options.isAddDynamicMenuRoutes = false
32
    router.push({ name: 'login' })
34
  }
33
  }
35
  return response
34
  return response
36
}, error => {
35
}, error => {

+ 2 - 3
src/views/main-navbar.vue

102
          }).then(({data}) => {
102
          }).then(({data}) => {
103
            if (data && data.code === 0) {
103
            if (data && data.code === 0) {
104
              this.$cookie.delete('token')
104
              this.$cookie.delete('token')
105
              this.$router.push({ name: 'login' }, () => {
106
                location.reload() // 刷新页面, 清空整站临时存储数据
107
              })
105
              this.$router.options.isAddDynamicMenuRoutes = false
106
              this.$router.push({ name: 'login' })
108
            }
107
            }
109
          })
108
          })
110
        }).catch(() => {})
109
        }).catch(() => {})