v-show="showAbs"
来源:9-3 Vue项目详情页 - 实现Header渐隐渐显效果
慕仙9082012
2023-01-09
请问老师,
1、为什么我这里showAbs设置为true的时候,这个header-abs-back反而显示不出来,要v-show=!showAbs"才能显示?
<template>
<div>
<router-link class="header-abs" to="/" tag="div" v-show="!showAbs">
<div class="iconfont header-abs-back"></div>
</router-link >
<div class="header-fixed" v-show="showAbs">
景点详情
<router-link to="/">
<div class="iconfont header-fixed-back"></div>
</router-link>
</div>
</div>
</template>
2、这里报错,说我的showAbs未定义是为什么?
```<template>
<div>
<router-link class="header-abs" to="/" tag="div" v-show="showAbs">
<div class="iconfont header-abs-back"></div>
</router-link >
<div class="header-fixed" v-show="!showAbs">
景点详情
<router-link to="/">
<div class="iconfont header-fixed-back"></div>
</router-link>
</div>
</div>
</template>
<script>
export default{
name: 'DetailHeader',
data () {
return {
showAbS: true
}
},
activated () {
window.addEventListener('scroll', this.handleScroll)
},
methods: {
handleScroll () {
const top = document.documentElement.scrollTop
if (top > 60) {
this.showAbS = true
} else {
this.showAbS = false
}
}
}
}
</script>
<style lang="stylus" scoped>
@import '~styles/variables.styl'
.header-abs
top .2rem
left: .2rem
position: absolute
width: .8rem
height: .8rem
line-height .8rem
border-radius: .4rem
background: rgba(0, 0, 0, 0.8)
text-align: center
.header-abs-back
color: #fff
font-size .4rem
.header-fixed
position: fixed
top: 0
left: 0
right: 0
line-height: .86rem
color: #fff
text-align: center
background: $bgColor
font-size: .32rem
.header-fixed-back
float: left
position: absolute
width .64rem
top: 0
left: 0
texy-align: center
font-size .4rem
color #fff
</style>
写回答
1回答
-
慕仙9082012
提问者
2023-01-10
<template> <div> <router-link class="header-abs" to="/" tag="div" v-show="!showAbs"> <div class="iconfont header-abs-back"></div> </router-link > <div class="header-fixed" v-show="showAbS"> 景点详情 <router-link to="/"> <div class="iconfont header-fixed-back"></div> </router-link> </div> </div> </template> <script> export default{ name: 'DetailHeader', data () { return { showAbS: false } }, methods: { handleScroll () { const top = document.documentElement.scrollTop if (top > 60) { this.showAbS = true } else { this.showAbS = false } } },
把showAbs设置成false就可以完成效果,但是还是显示报错,请问老师这是为什么?
012023-02-01
相似问题