PullRefresh - Vant 4
PullRefresh
Intro
Used to provide interactive operations for pull-down refresh.
Install
Register component globally via app.use, refer to Component Registration for more registration ways.
js
import { createApp } from'vue'; import { PullRefresh } from'vant'; const app = createApp(); app.use(PullRefresh);Usage
Basic Usage
The refresh event will be Emitted when pull refresh, you should set v-model to false to reset loading status after process refresh event.
html
js
import { ref } from'vue'; import { showToast } from'vant'; exportdefault { setup() { const count = ref(0); const loading = ref(false); constonRefresh = () => { setTimeout(() => { showToast('Refresh Success'); loading.value = false; count.value++; }, 1000); }; return { count, loading, onRefresh, }; }, };Success Tip
Use success-text to set the success prompt after the refresh is successful
html
Custom Tips
Use slots to custom tips.
html
API
Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| v-model | Loading status | boolean | - |
| pulling-text | Text to show when pulling | string | Pull to refresh... |
| loosing-text | Text to show when loosing | string | Loose to refresh... |
| loading-text | Text to show when loading | string | Loading... |
| success-text | Text to show when loading success | string | - |
| success-duration | Success text display duration(ms) | *number | string* |
| animation-duration | Animation duration | *number | string* |
| head-height | Height of head | *number | string* |
| pull-distance | The distance to trigger the pull refresh | *number | string* |
| disabled | Whether to disable pull refresh | boolean | false |
Events
| Event | Description | Parameters |
|---|---|---|
| refresh | Emitted after pulling refresh | - |
| change | Emitted when draging or status changed | { status: string, distance: number } |
Slots
| Name | Description | SlotProps |
|---|---|---|
| default | Default slot | - |
| normal | Content of head when at normal status | - |
| pulling | Content of head when at pulling | { distance: number } |
| loosing | Content of head when at loosing | { distance: number } |
| loading | Content of head when at loading | { distance: number } |
| success | Content of head when succeed | - |
Types
The component exports the following type definitions:
ts
importtype { PullRefreshProps } from'vant';Theming
CSS Variables
The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
| Name | Default Value | Description |
|---|---|---|
| --van-pull-refresh-head-height | 50px | - |
| --van-pull-refresh-head-font-size | var(--van-font-size-md) | - |
| --van-pull-refresh-head-text-color | var(--van-text-color-2) | - |
| --van-pull-refresh-loading-icon-size | 16px | - |