<template>
  <div id="app" :style="'background-image:url(' + Background + ');'">
    <!-- <img alt="Vue logo" src="./assets/logo.png"> -->
    <router-view />
  </div>
</template>

<script>
// import login from './login.vue'
import Background from "@/assets/page_bj/bg_CAC.png";
export default {
  name: "App",
  // components: {
  //   login
  // }
  data() {
    return {
      Background: Background,
    };
  },
  destroyed() {
    window.removeEventListener("popstate", this.goBack, false);
  },
  mounted() {
    // 检测浏览器路由改变页面不刷新问题,hash模式的工作原理是hashchange事件
    window.addEventListener(
      "hashchange",
      () => {
        let currentPath = window.location.hash.slice(1);
        if (this.$route.path !== currentPath) {
          this.$router.push(currentPath);
        }
      },
      false
    );
    if (window.history && window.history.pushState) {
      history.pushState(null, null, document.URL);
      window.addEventListener("popstate", this.goBack, false);
    }
  },
  methods: {
    goBack() {
      this.$router.push({ path: "/" });
      //replace替换原路由，作用是避免回退死循环
    },
  },
};
</script>

<style>
#app {
  width: 100%;
  height: 100%;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  /* margin-top: 60px; */
}
</style>
