backtotop仅当用户滚动底部 > 250 时才需要显示按钮。我该怎么做?
我的代码:
<template>
<div>
<button v-if="checkScroll" class="goTop" @click="backToTop">
<i class="fa fa-angle-up" aria-hidden="true"></i>
</button>
</div>
</template>
<script>
export default {
methods: {
computed: {
checkScroll() {
if ($(document).scrollTop() > 250) {
return true;
} else {
return false;
}
}
},
backToTop() {
this.$scrollTo('html');
},
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我的代码不起作用。我不明白的错误。按钮被隐藏。