0.2.0 • Published 6 years ago

vue-awesome-scroll v0.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Vue-Awesome-Scroll

better-scroll component for Vue, support pc and mobile, SPA.

基于 better-scroll、适用于 Vue 的滚动组件。

Install

CDN

<script type="text/javascript" src="path/to/better-scroll.js"></script>
<script type="text/javascript" src="path/to/vue.min.js"></script>
<script type="text/javascript" src="path/to/dist/vue-awesome-scroll.js"></script>
<script type="text/javascript">
  Vue.use(window.VueAwesomeScroll)
</script>

NPM

npm install vue-awesome-scroll --save

Mount

mount with global

import Vue from 'vue'
import VueAwesomeScroll from 'vue-awesome-scroll'


Vue.use(VueAwesomeScroll, /* { default global options } */)

mount with component

import { bscroll } from 'vue-awesome-scroll'

export default {
  components: {
    bscroll
  }
}

SPA

<!-- The ref attr used to find the scroll instance -->
<template>
  <bscroll :options="scrollOption" ref="myScroll" @someScrollEvent="callback">

  </bscroll>
</template>

<script>
  export default {
    name: 'carrousel',
    data() {
      return {
        scrollOption: {
          // some scroll options/callbacks
          // 所有的参数同 scroll 官方 api 参数
          // ...
           pullUpLoad: {
                    threshold: 0, //负数表示向上拉多少更新,正数表示距离底部还有多少时就去更新
                    txt: {
                        more: "加载更多...",
                        noMore: "没有更多历史版本了"
                    }
           },
           pullDownRefresh: {
                        threshold: 60,
                        stopTime: 1000,
                        txt: '更新成功'
           },
           bounceTime: 1000,
        }
      }
    },
    computed: {
      scroll() {
        return this.$refs.myScroll.scroll
      }
    },
    mounted() {
      // current scroll instance
      // 然后你就可以使用当前上下文内的scroll对象去做你想做的事了
      console.log('this is current scroll instance object', this.scroll)
    }
  }
</script>

Props 配置:

参数说明类型可选值默认值
optionsbetter-scroll 配置项,具体请参考BS 官方文档Object-{ observeDOM: true, click: true, probeType: 1, scrollbar: false, pullDownRefresh: false, pullUpLoad: false }

options中 better-scroll 的几个常用配置项,pullDownRefreshpullUpLoad这两个配置即可设为 Booleanfalse 关闭该功能,true 开启该功能,并使用默认子配置),也可设为Object,开启该功能并具体定制其子配置项。

  • pullDownRefresh 子配置项
参数说明类型可选值默认值
threshold下拉刷新动作的下拉距离阈值Number-90
stop回弹停留的位置Number-组件会自动计算回弹时显示的元素高度作为默认值
stopTime刷新成功的文案显示时间Number-600
txt刷新成功的文案String-'Refresh success'
  • pullUpLoad 子配置项
参数说明类型可选值默认值
threshold上拉刷新动作的上拉距离阈值Number-0
txt上拉加载的相关文案Object-{ more: '', noMore: '' }

TO DO

  • pull up to load
  • pull down to refresh
  • add exmaple
  • add test
  • add key point to use better-scroll

API

Scroll's API and configuration can be used.(Scroll官网中的API及配置均可使用)

Author

Surmon