watch: {
// 根据路由监听判断是否是登录状态
$route: function(val) {
this.currentRoute = val.path;
if (val.path === "/") {
this.isLogin = false;
} else {
this.isLogin = true;
}
},
},
<template>
<div v-if="isLogin">
<div>头部</div>
</div>
</template>
<script>
export default {
name: "index",
data(){
return{
isLogin:false,
currentRoute: "", // 当前路由
}
},
// 监听路由
watch: {
// 根据路由监听判断是否是登录状态
$route: function(val) {
this.currentRoute = val.path;
if (val.path === "/") {
this.isLogin = false;
} else {
this.isLogin = true;
}
},
},
}
</script>
<style scoped>
</style>