<template>
  <div id="app" scrolling="no">
    <router-view/>
  </div>
</template>
<script>
export default {
  name: 'App',
  data() {
    return {
      beforeUnload_time: ''
    }
  },
  mounted() {
    window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
    window.addEventListener('unload', e => this.unloadHandler(e))
  },
  destroyed() {
    window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
    window.removeEventListener('unload', e => this.unloadHandler(e))
  },
  methods: {
    beforeunloadHandler() {
      this.beforeUnload_time = new Date().getTime()
    },
    unloadHandler(e) {
      var gap_time = new Date().getTime() - this.beforeUnload_time
      // 判断是窗口关闭还是刷新
      if (gap_time <= 5) {
        if (this.$root.ws !== null) {
          this.$root.ws.close()
          this.$root.ws = null
        }
      }
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss">
  body .el-table th.gutter{
    display: table-cell!important;
  }
</style>
