<template> <div class="home"> <span type="text" v-if="btnFlag" class="FloatWin_l FloatWin_p" @click="backTop">返回顶部</span> </div> </template> <script> import generalView from './component/generalView' import historySub from './component/historySub' export default { name: "healthy", components:{ generalView, historySub }, data(){ return{ btnFlag: false, } }, methods: { // 点击图片回到顶部方法,加计时器是为了过渡顺滑 backTop() { const that = this let timer = setInterval(() => { let ispeed = Math.floor(-that.scrollTop / 5) document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + ispeed if (that.scrollTop === 0) { clearInterval(timer) } }, 16) }, // 为了计算距离顶部的高度,当高度大于60显示回顶部图标,小于60则隐藏 scrollToTop() { const that = this let scr