vue设置30分钟不进行任何操作跳转到登录页面

在App.vue添加代码 

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

<script>
export default {
  name: 'App',
  data() {
    return {
      timmer: null
    }
  },
  methods: {
    moveEvent: function() {
      let path = ['/login']
      if(!path.includes(this.$route.path)) {
        clearTimeout(this.timmer)
        this.init()
      }
    },
    init: function() {
      this.timmer = setTimeout(() => {
        sessionStorage.clear()
        this.$router.push({
          path: '/login'
        })
      }, 1000*60*30)
    }
  }
}
</script>

延时的时间单位是毫秒 1000*60*30就是30分钟,可以根据要求的时间进行修改

posted @ 2019-12-11 17:30  努力加油进步  阅读(182)  评论(0)    收藏  举报