1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <template>
- <div id="app">
- <router-view />
- </div>
- </template>
- <script>
- import { removeToken } from '@/utils/auth'
- export default {
- name: 'App',
- data() {
- return {
- beforeUnloadTime: '',
- gapTime: ''
- }
- },
- mounted() {
- window.addEventListener('beforeunload', e => {
- const { path } = this.$route
- if (!path.includes('/perview')) {
- this.beforeUnloadTime = new Date().getTime()
- }
- })
- window.addEventListener('unload', async() => {
- const { path } = this.$route
- if (!path.includes('/perview')) {
- this.gapTime = new Date().getTime() - this.beforeUnloadTime
- if (this.gapTime <= 5) {
- // 关闭
- // 清除 cookie 或者 localStorage 的方法
- removeToken()
- } else {
- // 刷新
- }
- }
- })
- },
- destroyed() {
- window.removeEventListener('beforeunload')
- window.removeEventListener('unload')
- }
- }
- </script>
|