<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue';
const beforeunloadHandler = () => {
  logout()
}

onMounted(() => {
  window.addEventListener('beforeunload', e => beforeunloadHandler(e))
})

onBeforeUnmount(() => {
  window.removeEventListener('beforeunload', e => beforeunloadHandler(e))
})

function logout() {
  localStorage.removeItem('token')
  localStorage.removeItem('userInfo')
  router.replace("/login")
}
</script>

<template>
  <!-- 一级路由出口组件 -->
  <RouterView />
</template>

<style scoped lang="scss">
.test {
  color: $priceColor
}
</style>
