vue 在.vue文件里监听路由

监听路由  watch   $route

vue项目中的App.vue 文件

<template>
  <div id="app">
      <!--include=[AdminUserManage,createUser]-->
      <keep-alive >
          <router-view/>
      </keep-alive>
      <TabBer v-if="tabbarshow"/>

  </div>
</template>
<script>
import TabBer from './components/public/TabBar.vue'
export default {
    components:{
        TabBer,
    },
    data() {
        return {
        tabbarshow:false
        }
    },
     watch: {
        $route(to,from) {
            if(this.$route.path == "/Home"){
            this.tabbarshow = true
            }else if(this.$route.path =='/more'||this.$route.path =='/More'){
                this.tabbarshow = true
            }else{
                this.tabbarshow = false
            }
        }
     },
    created(){
        if(this.$route.path == "/Home"){
            this.tabbarshow = true
        }else if(this.$route.path =='/more'||this.$route.path =='/More'){
                this.tabbarshow = true
        }else{
            this.tabbarshow = false
        }
    }
}
</script>

<style>

</style>
原文地址:https://www.cnblogs.com/taohuaya/p/10374841.html