# PullRefresh 下拉刷新
下拉刷新:手势状态机 pulling → loosing → loading → success,位移阻尼换算
(dampenPull)与顶判定(canPull)全部消费 @lh-ui/share/core/pull-refresh
纯逻辑。web 三端手写 touch 手势。
下拉刷新(松手触发 + 成功提示)
<template>
<div class="demo-col" style="gap: 18px">
<div class="pull-demo-scroll">
<LhPullRefresh v-model="refreshing" :head-height="50" @refresh="onRefresh">
<div v-for="item in items" :key="item" class="pull-demo-item">条目 {{ item }}</div>
</LhPullRefresh>
</div>
<p class="demo-note">{{ items.length }} 条 · 已刷新 {{ times }} 次</p>
</div>
</template>
<script>
export default {
data: () => ({
refreshing: false,
items: [1, 2, 3],
times: 0,
}),
methods: {
onRefresh() {
setTimeout(() => {
this.times += 1
this.items = [1, 2, 3].map((i) => i + this.times * 3)
this.refreshing = false
}, 800)
},
},
}
</script>
# 自定义头部
head 具名插槽替换默认文案提示(作用域参数 { state }):
<LhPullRefresh v-model="refreshing">
<template #head="{ state }">
<span v-if="state === 'loading'">加载中…</span>
<span v-else>{{ state === 'loosing' ? '松手刷新' : '下拉刷新' }}</span>
</template>
<div>内容</div>
</LhPullRefresh>
# 禁用
<LhPullRefresh :model-value="false" disabled />
# Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| modelValue | 刷新中(受控,v-model;使用方拉完数据置 false) | boolean | false |
| headHeight | 头部高度 / 触发阈值 px | number | 50 |
| pullingText | 下拉提示(未传走语言包 pullRefresh.pulling) | string | — |
| loosingText | 释放提示(未传走语言包 pullRefresh.loosing) | string | — |
| loadingText | 刷新中提示(未传走语言包 pullRefresh.loading) | string | — |
| successText | 成功提示(未传走语言包 pullRefresh.success) | string | — |
| disabled | 禁用下拉 | boolean | false |
| sx | sx 快速布局属性 | LhSxProps | — |
# Events
| 事件 | 说明 | 载荷 |
|---|---|---|
| update:modelValue | 刷新态变化(触发 / 结束刷新回写,v-model 路径) | value: boolean |
| refresh | 到顶下拉过阈值后释放:使用方拉数据后置 modelValue=false | — |
# Slots
| 名称 | 说明 |
|---|---|
| default | 页面内容 |
| head | 自定义头部(作用域参数 { state }) |
# 无障碍
根元素 aria-busy 反映刷新中。
Copyright © 2024-2026 风默文学 | 宁ICP备2024006574号 |
苏公网安备32040002010537