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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章