ant-design-vue/components/list/demo/loadmore.md

89 lines
2.1 KiB
Markdown
Raw Normal View History

2018-06-16 13:30:41 +00:00
<cn>
#### 加载更多
可通过 `loadMore` 属性实现加载更多功能。
</cn>
<us>
#### Load more
Load more list with `loadMore` property.
</us>
2019-10-09 10:32:23 +00:00
```tpl
2018-06-16 13:30:41 +00:00
<template>
2019-09-28 12:45:07 +00:00
<a-list class="demo-loadmore-list" :loading="loading" itemLayout="horizontal" :dataSource="data">
<div
v-if="showLoadingMore"
slot="loadMore"
:style="{ textAlign: 'center', marginTop: '12px', height: '32px', lineHeight: '32px' }"
>
2018-06-16 13:30:41 +00:00
<a-spin v-if="loadingMore" />
<a-button v-else @click="onLoadMore">loading more</a-button>
</div>
<a-list-item slot="renderItem" slot-scope="item, index">
<a slot="actions">edit</a>
<a slot="actions">more</a>
<a-list-item-meta
description="Ant Design, a design language for background applications, is refined by Ant UED Team"
>
2019-12-10 09:28:57 +00:00
<a slot="title" href="https://www.antdv.com/">{{item.name.last}}</a>
2019-09-28 12:45:07 +00:00
<a-avatar
slot="avatar"
src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
/>
2018-06-16 13:30:41 +00:00
</a-list-item-meta>
<div>content</div>
</a-list-item>
</a-list>
</template>
<script>
2019-09-28 12:45:07 +00:00
import reqwest from 'reqwest';
2018-06-16 13:30:41 +00:00
2019-09-28 12:45:07 +00:00
const fakeDataUrl = 'https://randomuser.me/api/?results=5&inc=name,gender,email,nat&noinfo';
2018-06-16 13:30:41 +00:00
2019-09-28 12:45:07 +00:00
export default {
data() {
return {
loading: true,
loadingMore: false,
showLoadingMore: true,
data: [],
};
2018-06-16 13:30:41 +00:00
},
2019-09-28 12:45:07 +00:00
mounted() {
this.getData(res => {
this.loading = false;
this.data = res.results;
});
2018-06-16 13:30:41 +00:00
},
2019-09-28 12:45:07 +00:00
methods: {
getData(callback) {
reqwest({
url: fakeDataUrl,
type: 'json',
method: 'get',
contentType: 'application/json',
success: res => {
callback(res);
},
});
},
onLoadMore() {
this.loadingMore = true;
this.getData(res => {
this.data = this.data.concat(res.results);
this.loadingMore = false;
this.$nextTick(() => {
window.dispatchEvent(new Event('resize'));
});
});
},
},
};
2018-06-16 13:30:41 +00:00
</script>
<style>
2019-09-28 12:45:07 +00:00
.demo-loadmore-list {
min-height: 350px;
}
2018-06-16 13:30:41 +00:00
</style>
```