<template>
  <van-nav-bar
    :title="title"
    left-text=""
    left-arrow
    @click-left="back"
  >
    <van-icon :name="backHome ? 'wap-home' : 'arrow-left'" slot="left" />
  </van-nav-bar>
</template>

<script>
export default {
  name: "NavBar",
  data() {
    return {
      backHome: false
    };
  },
  props: {
    title: {
      type: String,
      required: true,
      default: ""
    }
  },
  created: function() {
    if (this.$util.sessionStorage.fetch("backHome")) {
      this.backHome = true;
    }
  },
  mounted: function() {},
  methods: {
    // 返回
    back() {
      if (this.backHome) {
        this.$util.sessionStorage.remove("backHome");
        this.$router.push("/");
      } else {
        window.history.length > 1
          ? window.history.go(-1)
          : this.$router.push("/");
      }
    }
  }
};
</script>

<style scoped lang="less">
</style>
