Vant PullRefresh 下拉刷新功能
发布时间:2023-04-20 12:37:13 所属栏目:教程 来源:
导读:Vant PullRefresh 组件主要实现手机端的下拉刷新功能。
引入
import Vue from 'vue';
import { PullRefresh } from 'vant';
Vue.use(PullRefresh);
基础用法
下拉刷新时会触发 refresh 事
引入
import Vue from 'vue';
import { PullRefresh } from 'vant';
Vue.use(PullRefresh);
基础用法
下拉刷新时会触发 refresh 事
Vant PullRefresh 组件主要实现手机端的下拉刷新功能。 引入 import Vue from 'vue'; import { PullRefresh } from 'vant'; Vue.use(PullRefresh); 基础用法 下拉刷新时会触发 refresh 事件,在事件的回调函数中可以进行同步或异步操作,操作完成后将 v-model 设置为 false,表示加载完成。 <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); } } } 成功提示 通过success-text可以设置刷新成功后的顶部提示文案 <van-pull-refresh v-model="isLoading" success-text="刷新成功" @refresh="onRefresh" > <p>刷新次数: {{ count }}</p> </van-pull-refresh> 自定义提示 通过插槽可以自定义下拉刷新过程中的提示内容 <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> (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |