vue-element-template 後臺管理設置超時自動退出登錄

簡單實現,修改app.vue文件即可

<template>
  <div id="app"  @click="clicked">
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'App',
  data (){
    return {
        clickTime: new Date().getTime(),
        tOut: 5 * 60 * 1000
    }
  },
  methods:{
    clicked () {
      // console.log(new Date().getTime() - this.clickTime)
      if ((new Date().getTime() - this.clickTime) > this.tOut) {
        if (this.$store.getters.token) {
          this.$store.dispatch('FedLogOut').then(() => {
            this.$alert('超時未操作,請重新登錄。', '提示', {
              confirmButtonText: '確定'
            }).then(() => {
              location.reload()
            })
          })
        }
      }
      this.clickTime = new Date().getTime() 
    },
  },
}
</script>
發佈了264 篇原創文章 · 獲贊 202 · 訪問量 110萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章