CurrentTime = lastTime; currentTime = lastTime; currentTime = lastTime

// The file name is astrict.js
let lastTime = new Date().getTime()
let currentTime = new Date().getTime()
const timeOut = 30 * 60 * 1000 // Set the timeout period to 30 minutes
let timeRunning

window.onload = function () {
  window.document.onmouseover = function () {
    lastTime = new Date().getTime() / / update the lastTime}}function checkTimeout () {
  currentTime = new Date().getTime() // Update the current time
  if (currentTime - lastTime > timeOut) { // Determine whether timeout occurs
    // Clear the timer
    clearInterval(timeRunning)
    // Clear the cache
    window.localStorage.clear()
    // Jump to the login page
    /* Jump code */}}export default function () {
  timeRunning = window.setInterval(checkTimeout, 30 * 1000) // Set the monitoring time: 30s/ time
}
Copy the code

At the end of the page to call import again reference OK

import Astrict from '@/utils/astrict'

Astrict() // Logout timeout judgment
Copy the code