提交 e9537e46 编写于 作者: J JiZhi 提交者: doly mood

Recycle list add api (#417)

* docs(recycle-list): add clean methods

* feat(recycle-list): add clean methods

* test(recycle-list): test clean methods

* docs(recycle-list): change clean to reset

* feat(recycle-list): change clean method to reset method

* test(recycle-list): test list length of recycle-list

* test(recycle-list): optimize unit case
上级 e89a5a5b
......@@ -144,3 +144,9 @@ The `onFetch` function must return a Promise, and the first argument to Promise'
| item | Scope slot for each data item | data: An item in items |
| spinner | Named slot for loading more | - |
| noMore | Named slot for no more data | - |
### Instance methods
| Method name | Description |
| - | - |
| reset | To clean up all the contents |
......@@ -144,3 +144,9 @@
| item | 列表某项的作用域插槽,通过此插槽实现想要的渲染视图 | data: 调用方传入的数据项集合的某一项 |
| spinner | 加载更多的提示文案的具名插槽 | - |
| noMore | 无更多数据的提示文案的具名插槽 | - |
### 实例方法
| 方法名 | 说明 |
| - | - |
| reset | 清空列表全部内容,重置数据 |
......@@ -263,6 +263,43 @@
}
}
},
reset () {
const map = [
{
key: 'items',
value: []
},
{
key: 'heights',
value: 0
},
{
key: 'startIndex',
value: 0
},
{
key: 'loadings',
value: []
},
{
key: 'noMore',
value: false
},
{
key: 'list',
value: []
},
{
key: 'promiseStack',
value: []
}
]
map.forEach(({ key, value }) => {
this[key] = value
})
this.$el.scrollTop = 0
this.load()
},
_onScroll() {
// trigger load
if (!this.noMore && this.$el.scrollTop + this.$el.offsetHeight > this.heights - this.offset) {
......
......@@ -47,6 +47,21 @@ describe('RecycleList', () => {
}, 500)
}, 500)
})
it('should clean all contents', (done) => {
vm = createRecycleList(true)
setTimeout(() => {
vm.$parent.reset()
vm.reset()
expect(vm.list.length)
.to.equal(0)
setTimeout(() => {
expect(vm.list.length)
.to.equal(10)
done()
}, 500)
}, 500)
})
it('should call correct method', (done) => {
vm = createRecycleList()
setTimeout(() => {
......@@ -82,6 +97,9 @@ function createRecycleList (infinite) {
}
},
methods: {
reset () {
this.pid = 0
},
onFetch () {
let items = []
this.pid += 1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册