我一点返回顶部就这样
来源:7-1 返回顶部组件
慕盖茨6589387
2019-08-29 16:48:47
//base/back <template> <transition name="mine-backtop"> <a href="javascript:;" class="mine-backtop" v-show="visible" @click="backToTop" > <i class="iconfont icon-backtop"></i> </a> </transition> </template> <script> export default { name: 'MeBacktop', props: { visible: { type: Boolean, default: false } }, methods: { backToTop() { this.$emit('backtop'); } } }; </script> <style lang="scss" scoped> @import "~assets/scss/mixins"; .mine-backtop { overflow: hidden; @include flex-center(); width: 45px; height: 45px; background-color: rgba(0, 0, 0, 0.6); border: none; border-radius: 50%; .iconfont { color: #fff; font-size: 38px; } } .mine-backtop { &-enter-active, &-leave-active { transition: opacity 0.4s; } &-enter, &-leave-to { opacity: 0; } } </style> //home/index <template> <div class="home"> <header class="g-header-container"> <home-header></home-header> </header> <me-scroll :data="recommends" pullDown pullUp @pull-down="pullToRefresh" @pull-up="pullToLoadMore" @scroll-end="scrollEnd" ref="scroll" > <home-slider ref="slider"></home-slider> <home-nav></home-nav> <home-recommend @loaded="getRecommends" ref="recommend"/> </me-scroll> <div class="g-backtop-container"> <me-backtop :visible="isBacktopVisible" @backtop="backToTop"></me-backtop> </div> <router-view></router-view> </div> </template> <script> import HomeHeader from './header'; import HomeSlider from './slider'; import MeScroll from 'base/scroll'; import MeBacktop from 'base/backtop'; import HomeNav from './nav'; import HomeRecommend from './recommend'; export default { name: 'Home', components: { HomeHeader, HomeSlider, MeScroll, HomeNav, HomeRecommend, MeBacktop }, data() { return { recommends: [], isBacktopVisible: false }; }, methods: { updataScroll() { }, getRecommends(recommends) { this.recommends = recommends; }, pullToRefresh(end) { this.$refs.slider.update().then(end); // setTimeout(() => { // console.log('下拉刷新'); // end(); // }, 1000); }, pullToLoadMore(end) { this.$refs.recommend.update().then(end).catch(err => { if (err) { console.log(err); } end(); }); }, scrollEnd(translate, scroll) { this.isBacktopVisible = translate < 0 && -translate > scroll.height; }, backToTop() { this.$refs.scroll && this.$refs.scroll.scrollToTop(); } } }; </script> <style lang="scss" scoped> @import "~assets/scss/mixins"; .home { overflow: hidden; width: 100%; height: 100%; background-color: $bgc-theme; } </style>
1回答
好帮手慕言
2019-08-29
同学你好,从报错信息上看,是speed没有定义,在同学提供的代码里面没有这个变量。
scroll/index.vue文件里面用到了speed,同学可以把自己的代码与老师的代码做对比,看哪个地方书写的不正确。
如果不能解决,可以把scroll/index.vue的代码粘贴上来,老师帮助测试。
如果帮助到了你,欢迎采纳~祝学习愉快~
相似问题