zoukankan      html  css  js  c++  java
  • vue慕课网音乐项目手记:9-封装一个公用的scroll组件

    知道disable是干什么的了,如果不加,scroll的高度会高于内容的高度。

    <template>  
      <div ref="wrapper">  
        <slot></slot>  
      </div>  
    </template>  
      
    <script>  
    import BScroll from 'better-scroll'  
    export default {  
      props: {  
        // probeType: 1 滚动的时候会派发scroll事件,会截流。2滚动的时候实时派发scroll事件,不会截流。 3除了实时派发scroll事件,在swipe的情况下仍然能实时派发scroll事件  
        probeType: {  
          type: Number,  
          default: 1  
        },  
        // click: true 是否派发click事件,通常判断浏览器派发的click还是betterscroll派发的click,可以用event._constructed,若是bs派发的则为true  
        click: {  
          type: Boolean,  
          default: true  
        },  
        data: {  
          type: Array,  
          default: null  
        }  
      },  
      mounted () {  
        setTimeout(() => {  
          this._initScroll()  
        }, 20)  
      },  
      methods: {  
        _initScroll () {  
          if (!this.$refs.wrapper) {  
            return  
          }  
          this.scroll = new BScroll(this.$refs.wrapper, {  
            probeType: this.probeType,  
            click: this.click  
          })  
        },  
        enable () {  
          // 启用 better-scroll,默认开启  
          this.scroll && this.scroll.enable()  
        },  
        // disable () {  
        //   // 禁用 better-scroll  
        //   this.scroll && this.scroll.disable()  
        // },  
        refresh () {  
          // 强制 scroll 重新计算,当 better-scroll 中的元素发生变化的时候调用此方法  
          this.scroll && this.scroll.refresh()  
        }  
      },  
      watch: {  
        data () {  
          setTimeout(() => {  
            this.refresh()  
          }, 20)  
        }  
      }  
    }  
    </script>  
      
    <style scoped>  
      
    </style>  

    使用如下:

    优化:

  • 相关阅读:
    读《奇点临近》
    C++中rand()函数的用法
    第四届蓝桥杯 c/c++真题
    ACM做题过程中的一些小技巧
    树状数组
    go单元测试进阶篇
    浓缩的才是精华:浅析GIF格式图片的存储和压缩
    腾讯IVWEB团队:WebRTC 点对点直播
    Mongodb Geo2d索引原理
    Unity编译Android的原理解析和apk打包分析
  • 原文地址:https://www.cnblogs.com/catbrother/p/9181102.html
Copyright © 2011-2022 走看看