May 07, 2021 Vant
import Vue from 'vue';
import { PullRefresh } from 'vant';
Vue.use(PullRefresh);
The refresh event is triggered when the pull-down refresh is triggered, and synchronization or asynchronous operations can be performed in the callback function of the event, and the v-model is set to false when the operation is complete, indicating that the load is complete.
<van-pull-refresh v-model="isLoading" @refresh="onRefresh">
<p>刷新次数: {{ count }}</p>
</van-pull-refresh>
import { Toast } from 'vant';
export default {
data() {
return {
count: 0,
isLoading: false
}
},
methods: {
onRefresh() {
setTimeout(() => {
Toast('刷新成功');
this.isLoading = false;
this.count++;
}, 1000);
}
}
}
The success-text allows you to set the top prompt file after a successful refresh
<van-pull-refresh
v-model="isLoading"
success-text="刷新成功"
@refresh="onRefresh"
>
<p>刷新次数: {{ count }}</p>
</van-pull-refresh>
The slot allows you to customize the prompts during the pull-down refresh process
<van-pull-refresh v-model="isLoading" :head-height="80" @refresh="onRefresh">
<!-- 下拉提示,通过 scale 实现一个缩放效果 -->
<img
class="doge"
slot="pulling"
slot-scope="props"
src="https://img.yzcdn.cn/vant/doge.png" rel="external nofollow" rel="external nofollow"
:style="{ transform: `scale(${props.distance / 80})` }"
>
<!-- 释放提示 -->
<img
class="doge"
slot="loosing"
src="https://img.yzcdn.cn/vant/doge.png" rel="external nofollow" rel="external nofollow"
>
<!-- 加载提示 -->
<img
class="doge"
slot="loading"
src="https://img.yzcdn.cn/vant/doge-fire.jpg" rel="external nofollow"
>
<p>刷新次数: {{ count }}</p>
</van-pull-refresh>
<style>
.doge {
width: 140px;
height: 72px;
margin-top: 8px;
border-radius: 4px;
}
</style>
Parameters | Description | Type | The default |
---|---|---|---|
v-model | Whether it is in a loaded state | boolean | - |
pulling-text | The pull-down process prompts the document | string |
下拉即可刷新...
|
loosing-text | The release process prompts the document | string |
释放即可刷新...
|
loading-text | The loading process prompts the file | string |
加载中...
|
success-text | Refresh success prompts the document | string | - |
success-duration | Refresh Success Prompt Presentation Time (ms) | number | string |
500
|
animation-duration | The length of the animation | number | string |
300
|
head-height
v2.4.2
|
The height of the top content | number | string |
50
|
disabled | Whether to disable pull-down refresh | boolean |
false
|
The name of the event | Description | Callback parameters |
---|---|---|
refresh | Triggered when a pull-down refresh | - |
Name | Description | SlotProps |
---|---|---|
default | Custom content | - |
normal | Top content when not in a pull-down state | - |
pulling | The top content during the pull-down process | Distance: Current pull-down distance |
loosing | Release the top content during the process | Distance: Current pull-down distance |
loading | The top content during the loading process | Distance: Current pull-down distance |
success | Refresh the successful prompt content | - |