Vue record return function, no display after first entry

 

Home Home.vue

<!-- 顶部 Header 区域 -->
<mt-header fixed title="Vue项目">
   <span slot="left" @click="goBack" v-show="flag">
        <mt-button icon="back">返回</mt-button>
   </span>
</mt-header>

 

<script>
export default {
  data() {
    return {
      flag: false
    };
  },
  created() {
    this.flag = this.$route.path === "/home" ? false : true;
  },
  methods: {
    goBack() {
      // 点击后退
      this.$router.go(-1);
    }
  },
  watch: {
    "$route.path": function(newVal) {
      if (newVal === "/home") {
        this.flag = false;
      } else {
        this.flag = true;
      }
    }
  }
};
</script>

 

Guess you like

Origin blog.csdn.net/SmartJunTao/article/details/108260602