https://www.imooc.com/article/25858

https://github.com/cube-ui/cube-application-guide

https://www.jishux.com/plus/view-651615-1.html

https://www.jianshu.com/p/48167450e5c1


配置:

packjson


导入:

import Vue from 'vue' ;

import {Style,Scroll} from 'cube-ui';  也可以按需引入  


使用:

html 中

<cube-scroll
  ref="scroll"
  :data="pullData"
  :options="options"
  @pulling-down="onPullingDown"
  @pulling-up="onPullingUp">
  <p>要滚动的区域</p>
</cube-scroll>

Vue.js中


配置选项:

//  TODO 测试下拉刷新,上拉加载的数据
data: {
pullData: [],
options: {
  pullDownRefresh: {
    threshold: 90,
    stop: 40,
    txt: '刷新成功'
  },
  pullUpLoad: {
    threshold: 0,
      txt: {
      more: '上拉加载更多...',
        noMore: '没有更多数据...'
    }
  }
},
}
 
methods: {

  // TODO 下拉刷新
  onPullingDown: function(){
    console.log("下拉刷新" + this.pullData);
    // Mock async load.
    setTimeout(() => {
      if (Math.random() > 0.5) {
        // 如果有最新数据,数组开头追加数据
        this.pullData.unshift('I am new data: ' + +new Date())
      } else {
        // 没有数据。结束此次刷新
        this.$refs.scroll.forceUpdate()
      }
    }, 1000)
  },
  //TODO 上拉加载
  onPullingUp: function() {
    console.log("上拉加载" + this.pullData);
    // Mock async load.
    setTimeout(() => {
      if (Math.random() > 0.5) {
        // 如果有最新数据,数组末尾追加数据
        let newPage = [
          'I am line ' + ++this.itemIndex,
          'I am line ' + ++this.itemIndex,
          'I am line ' + ++this.itemIndex,
          'I am line ' + ++this.itemIndex,
          'I am line ' + ++this.itemIndex
        ];

        this.pullData = this.pullData.concat(newPage);
      } else {
        // 没有数据,结束此次刷新
        this.$refs.scroll.forceUpdate()
      }
    }, 1000)
  },
}
 

Logo

前往低代码交流专区

更多推荐