# jroll-vue-infinite2

> JRoll无限加载 for Vue2

Latest version **2.0.2** (published 2018-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install jroll-vue-infinite2
pnpm add jroll-vue-infinite2
yarn add jroll-vue-infinite2
bun add jroll-vue-infinite2
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2018-07-13 |
| First published | 2017-11-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 455 |
| Author | BarZu |
| Maintainers | chjtx |
| Keywords | jroll-vue-infinite |

## Links

- npm: https://www.npmjs.com/package/jroll-vue-infinite2
- Repository: https://github.com/chjtx/JRoll
- Homepage: https://github.com/chjtx/JRoll/tree/master/extends/jroll-vue-infinite2
- Issues: https://github.com/chjtx/JRoll/issues
- npm.io page: https://npm.io/package/jroll-vue-infinite2

## Recent versions

- 2.0.2 (latest) — 2018-07-13
- 2.0.1 — 2018-01-06
- 2.0.0 — 2017-11-29

## README

# JRoll无限加载+下拉刷新 for Vue2 （第二版）

## 示例

```html
<jroll-infinite class="jroll-vue-infinite"
  total="10"
  :jroll-options="options"
  @on-scroll-bottom="scrollBottom"
  @on-scroll-start="scrollStart"
  @on-scroll="scroll"
  @on-scroll-end="scrollEnd">
    <div class='item' v-for="i in items">{{i.index}}、{{i.text}}</div>
</jroll-infinite>
```

```js
Vue.component('jroll-infinite', JRoll.VueInfinite2())
```

> 注意：加载顺序必须先引入`jroll.js`再引入`jroll-vue-infinite2.js`

## NPM安装

```bash
npm i -D jroll
npm i -D jroll-vue-infinite2
```

## 选项

| 选项 | 默认值 | 必填 | 说明 |
|:----|:----:|:----:|----|
|total| 99 | 否 | 总页数 |
|:jroll-options| -- | 否 | 提供jroll的选项，参考[http://www.chjtx.com/JRoll/#options](http://www.chjtx.com/JRoll/#options) |
|@on-scroll-bottom| -- | 是 | 滑动到底部时执行，初始化时会执行一次，用于更新数据，`function (page, success, error)` |
|@on-scroll-start| -- | 否 | jroll的`scrollStart`事件，`function (jroll)` |
|@on-scroll| -- | 否 | jroll的`scroll`事件，`function (jroll)` |
|@on-scroll-end| -- | 否 | jroll的`scrollEnd`事件，`function (jroll)` |

## 无限加载

```html
<div id="app">
  <jroll-infinite class="jroll-vue-infinite" total="10" ref="myJRoll"
    :jroll-options="options"
    @on-scroll-bottom="scrollBottom"
    @on-scroll-start="scrollStart">
    <div class='item' v-for="i in items">{{i.index}}、{{i.text}}</div>
  </jroll-infinite>
</div>

<script>
new Vue({
  el: '#app',
  data: {
    page: 0,
    items: [],
    options: {
      scrollBarY: true
    }
  },
  mounted: function () {
    // 可以通过ref属性获取jroll对象
    console.log(this.$refs.myJRoll.jroll)
  },
  methods: {
    scrollBottom: function (page, success, error) {
      var me = this
      ajax({
        url: 'getData.do?page=' + (page + 1),
        success: function (data) {
          me.items = me.items.concat(data)
          success()
        },
        error: function () {
          error()
        }
      })
    },
    scrollStart: function (jroll) {
      // console.log(jroll)
    }
  }
})
</script>
```

## 开启下拉刷新功能

需要先引入`jroll-pulldown.js`，然后添加`:pulldown-options`选项和`@on-pulldown`事件

补充选项

| 选项 | 默认值 | 必填 | 说明 |
|:----|:----:|:----:|----|
|:pulldown-options| -- | 是 | 添加该选项才能开启下拉刷新，可为空对象，参考[https://github.com/chjtx/JRoll/tree/master/extends/jroll-pulldown](https://github.com/chjtx/JRoll/tree/master/extends/jroll-pulldown)，除`refresh`选项外，其余选项都有效 |
|@on-scroll-end| -- | 否 | jroll的`scrollEnd`事件，`function (jroll)` |

```html
<div id="app">
  <jroll-infinite class="jroll-vue-infinite" total="10" :pulldown-options="{}"
    @on-scroll-bottom="scrollBottom"
    @on-pulldown="pulldown">
    <div class='item' v-for="i in items">{{i.index}}、{{i.text}}</div>
  </jroll-infinite>
</div>

<script>
new Vue({
  el: '#app',
  data: {
    page: 0,
    items: []
  },
  methods: {
    pulldown: function (success, error) {
      var me = this
      ajax({
        url: 'getData.do?page=1',
        success: function (data) {
          me.items = data
          success()
        },
        error: function () {
          error()
        }
      })
    },
    scrollBottom: function (page, success, error) {
      var me = this
      ajax({
        url: 'getData.do?page=' + (page + 1),
        success: function (data) {
          me.items = me.items.concat(data)
          success()
        },
        error: function () {
          error()
        }
      })
    },
    scrollStart: function (jroll) {
      // console.log(jroll)
    }
  }
})
</script>
```

## 更新日志

### v2.0.2 (2018-07-13)

- 解决 vue-cli 3.0 使用 vue.runtime.esm.js 解释不了template的问题

### v2.0.1 (2018-01-06)

- 修复jrollOptions选项失效的问题
- 在`updated`方法里使用`$nextTick`解决滑动触发更新的问题

### v2.0.0 (2017-11-29)

- 发布`jroll-vue-infinite2`

---
_Source: https://npm.io/package/jroll-vue-infinite2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
