在App.vue对全局组件进行监听,利用v-if进行显示和隐藏
<template>
<div id="app">
<div v-if="headerShow">
<Head></Head>
</div>
<router-view/>
</div>
</template>
<script>
import Head from './components/head'
export default {
name: 'App',
data() {
return {
headerShow: true
}
},
components:{
Head
},
watch: {
$route(to, from) {
if (this.$route.path == "/login" || this.$route.path == "/register") {
this.headerShow = false;
} else {
this.headerShow = true;
}
}
}
}
</script>