<view class="right" @tap="toTop" v-show="flag">
<image style="width: 24px;height: 24px;" src="../../static/imges/icon_dingbu.png"> </image>
</view>
script:
export default {
data() {
return {
flag:false,
}
},
methods: {
//点击事件:返回顶部
toTop() {
document.documentElement.scrollTop = 0;//返回顶部
},
//滑动超过200时显示按钮
handleScroll() {
let scrollTop = document.documentElement.scrollTop;//获取页面滚动的高度
// console.log(scrollTop)
if (scrollTop > 200) {
this.flag = true
} else {
this.flag = false
}
},
},
mounted() {
window.addEventListener('scroll', this.handleScroll, true)
},
}
}