<template>
    <div id="app"  v-cloak :style="{position:(this.$route.path!='/moreGift' ? 'fixed':'')}">
        <Header></Header>
        <router-view v-if="isActive"></router-view>
    </div>
</template>

<script>
import Header from "./components/Header.vue";

export default {
  name: "App",
  props:{
      logoStatus:{
          type:Boolean,
          default:false,
      }
  },
    provide(){
        return {
            reload: this.reload
        }
    },
    data(){
        return{
            isActive:true
        }
    },

  components: {
    Header,
  },
  created() {

  },
  mounted(){
    if(localStorage.getItem("userinfo")){
      if(JSON.parse(localStorage.getItem("userinfo") == 'false') && this.$router.path!='/verification'){
          this.$router.push(
              {path: '/'},
              onComplete => {},
              onAbort => {}
          )
      }
    }
    if (window.history && window.history.pushState) {
      history.pushState(null, null, document.URL);
      window.addEventListener('popstate', this.goBack, false);
    }
  },
  //页面销毁时，取消监听。否则其他vue路由页面也会被监听
  destroyed(){
    window.removeEventListener('popstate', this.goBack, false);
  },
  //3、将监听操作写在methods里面，removeEventListener取消监听内容必须跟开启监听保持一致，所以函数拿到methods里面写
  methods:{
    reload(){
        this.isActive = false;
        this.$nextTick(() => {
            this.isActive  = true;
        })
    },
    goBack(){
      if(localStorage.getItem("userinfo")){
        this.$router.push(
            {path: '/home'},
            onComplete => {},
            onAbort => {}
         )
      }
      //replace替换原路由，作用是避免回退死循环
    }
  }

};
</script>

<style>
[v-cloak]{
    display: none;
}
#app {
    font-family: Lantinghei SC;
    height: 100%;
  /* font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale; */
}
</style>
