Files
vant/packages/list/en-US.md
T

96 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## List
A list component to show items and control loading status.
### Install
``` javascript
import { List } from 'vant';
Vue.use(List);
```
### Usage
#### Basic Usage
```html
<van-list
v-model="loading"
:finished="finished"
:error.sync="error"
finished-text="Finished"
error-text="Request failed. Click to reload..."
@load="onLoad"
>
<van-cell
v-for="item in list"
:key="item"
:title="item"
/>
</van-list>
```
```js
export default {
data() {
return {
list: [],
loading: false,
finished: false
error: false
};
},
methods: {
onLoad() {
setTimeout(() => {
for (let i = 0; i < 10; i++) {
this.list.push(this.list.length + 1);
}
this.loading = false;
// when error loaded:
// this.error = true;
if (this.list.length >= 40) {
this.finished = true;
}
}, 500);
}
}
}
```
### API
| Attribute | Description | Type | Default |
|------|------|------|------|
| loading | Whether to show loading infothe `load` event will not be triggered when loading | `Boolean` | `false` |
| finished | Whether loading is finishedthe `load` event will not be triggered when finished | `Boolean` | `false` |
| error | Whether loading is errorthe `load` event will be triggered only when error text clicked, the `sync` modifier is needed | `Boolean` | `false` |
| offset | The load event will be triggered when the distance between the scrollbar and the bottom is less than offset | `Number` | `300` |
| loading-text | Loading text | `String` | `Loading...` |
| finished-text | Finished text | `String` | - |
| error-text | Error loaded text | `String` | - |
| immediate-check | Whether to check loading position immediately after mounted | `Boolean` | `true` |
### Event
| Event | Description | Arguments |
|------|------|------|
| load | Triggered when the distance between the scrollbar and the bottom is less than offset | - |
### Methods
Use ref to get list instance and call instance methods
| Name | Attribute | Return value | Description |
|------|------|------|------|
| check | - | - | Check scroll position |
### Slot
| Name | Description |
|------|------|
| - | List content |
| loading | Custom loading tips |