一、在script标签中写入如下代码:判断当前进入的页面是否为不需要公共组件的页面,比如登录页面,不需要头部组件和尾部组件
mport { useRoute } from 'vue-router'
import { ref,watchEffect, } from "vue";
const route = useRoute()
const headershow=ref(true)
watchEffect(()=>{
if(route.path==="/login"){
headershow.value = false
}else{
headershow.value = true
}
})
二、在html标签中写入如下代码:定义一个class类,显示和隐藏。
<template>
<div class="contanier">
<!-- 顶部全局组件 -->
<div v-if="headershow">
<indexTop></indexTop>
</div>
<!-- 展示内容区域 -->
<div class="content">
<router-view></router-view>
</div>
<!-- 底部全局组件 -->
<div v-if="headershow">
<indexBottom></indexBottom>
</div>
</div>
</template>
注意:以上代码都是在App.vue跟组件里面实现的,因为是在全局下做路由判断。