62 lines
1.7 KiB
Vue
62 lines
1.7 KiB
Vue
<template>
|
|
<div class="sidebar-button" @click="$emit('toggle-sidebar')">
|
|
<svg class="icon" :style="{color:scrollFlag?'white':'black'}" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512">
|
|
<path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z" class=""></path>
|
|
</svg>
|
|
</div>
|
|
</template>
|
|
<script>
|
|
export default {
|
|
data(){
|
|
return{
|
|
scrollFlag: false
|
|
}
|
|
},
|
|
watch:{
|
|
//监听路由,处理导航栏样式
|
|
$route(to,from){
|
|
this.handleScroll();
|
|
}
|
|
},
|
|
methods:{
|
|
handleScroll () {
|
|
let _this=this;
|
|
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
|
|
// console.log(scrollTop)
|
|
let index = this.$route.path;
|
|
//当在首页的顶部时才加样式
|
|
if(scrollTop==0&&index== '/'){
|
|
_this.scrollFlag=true
|
|
// console.log("true");
|
|
}else{
|
|
_this.scrollFlag=false
|
|
// console.log("false");
|
|
}
|
|
}
|
|
},
|
|
mounted(){
|
|
this.handleScroll()
|
|
window.addEventListener('scroll', this.handleScroll)
|
|
}
|
|
}
|
|
</script>
|
|
<style lang="stylus">
|
|
.sidebar-button
|
|
cursor pointer
|
|
display none
|
|
width 1.25rem
|
|
height 1.25rem
|
|
position absolute
|
|
padding 0.6rem
|
|
top 0.6rem
|
|
left 1rem
|
|
.icon
|
|
display block
|
|
width 1.25rem
|
|
height 1.25rem
|
|
color white
|
|
@media (max-width: $MQMobile)
|
|
.sidebar-button
|
|
display block
|
|
</style>
|