Waterfall
组件类型:UxWaterfallComponentPublicInstance
支持配置间距,自动计算子项高度,支持子项自定义高度
平台兼容性
UniApp X
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
√ | √ | √ | x | √ |
UniApp Vue Nvue
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
x | x | √ | x | x |
Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
default | Slot | 默认slot | |
refresher | Slot | refresherslot | |
loadmore | Slot | loadmoreslot | |
backtop | Slot | backtopslot | |
crossAxisCount | Number | 2 | 交叉轴元素数量 |
mainAxisGap | Number | 0 | 主轴方向间隔 |
crossAxisGap | Number | 0 | 交叉轴方向间隔 |
padding | Array | [0,0,0,0] | 长度为4的数组,按top、right、bottom、left顺序指定内边距 |
associativeContainer | String | 关联的滚动容器 | |
bounces | Boolean | true | 控制是否回弹效果 |
upperThreshold | Number | 50 | 距顶部/左边多远时(单位px),触发scrolltoupper事件 |
lowerThreshold | Number | 50 | 距底部/右边多远时(单位px),触发scrolltolower事件 |
scrollTop | Number | 0 | 设置竖向滚动条位置 |
scrollIntoView | String | 值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素 | |
scrollWithAnimation | Boolean | true | 是否在设置滚动条位置时使用滚动动画,设置false没有滚动动画 |
refresherEnabled | Boolean | false | 开启下拉刷新 |
refresherThreshold | Number | 45 | 设置下拉刷新阈值 |
refresherMaxDragDistance | Number | 80 | 设置下拉最大拖拽距离(单位px) |
refresherBackground | String | transparent | 设置下拉刷新区域背景颜色 |
refresherTriggered | Boolean | false | 设置当前下拉刷新状态,true表示下拉刷新已经被触发,false表示下拉刷新未被触发 |
refresherStates | Array | 下拉刷新状态文案 | |
loadmoreEnabled | Boolean | false | 开启上拉加载 |
loadmoreStates | Array | 上拉加载状态文案 | |
showScrollbar | Boolean | false | 控制是否出现滚动条 |
customNestedScroll | Boolean | false | 子元素是否开启嵌套滚动将滚动事件与父元素协商处理 |
disabled | Boolean | false | 禁止滚动 |
background | String | transparent | 背景颜色 |
xstyle | Array | 自定义样式 |
associativeContainer
值 | 说明 |
---|---|
nested-scroll-view | 嵌套滚动 |
Events
事件名 | 说明 | 参数 |
---|---|---|
refresherpulling | 下拉刷新控件被下拉 | |
refresherrefresh | 下拉刷新被触发 | |
refresherrestore | 下拉刷新被复位 | |
refresherabort | 下拉刷新被中止 | |
loadmore | 上拉加载触发 | |
scrolltoupper | 滚动到顶部/左边,会触发scrolltoupper事件 | |
scrolltolower | 滚动到底部/右边,会触发scrolltolower事件 | |
scroll | 滚动时触发 | |
scrollend | 滚动结束时触发 |
示例代码
html
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :border="false">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-card direction="column" icon="flag-filled" title="瀑布流" :bold="true">
<!-- <template #subtitle>
<view style="width: 450rpx;">
<ux-slider :value="col" :max="5" :min="2" :show-value="true" unit="列" @change="change"></ux-slider>
</view>
</template> -->
<ux-text text="APP端封装的是系统的瀑布流组件, Web和小程序是自研组件, 用法和APP端保持一致"></ux-text>
</ux-card>
<ux-waterfall
ref="uxWaterfallRef"
:main-axis-gap="10"
:cross-axis-gap="10"
:padding="[10,10,10,10]"
:refresherEnabled="true"
:refresherTriggered="refresherTriggered"
:loadmoreEnabled="loadmoreEnabled"
:backtop="true"
@refresherrefresh="onRefresh"
@loadmore="onLoadmore">
<ux-waterfall-item :index="index" v-for="(item, index) in list" :key="index">
<view class="item">
<image class="img" :fade-show="true" :src="item['cover']" mode="widthFix"></image>
<text class="name">{{ item['author_name'] }}</text>
<text class="title">{{ item['title'] }}</text>
<text class="time">{{ item['published_at'] }}</text>
</view>
</ux-waterfall-item>
</ux-waterfall>
</ux-page>
</template>
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :border="false">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-card direction="column" icon="flag-filled" title="瀑布流" :bold="true">
<!-- <template #subtitle>
<view style="width: 450rpx;">
<ux-slider :value="col" :max="5" :min="2" :show-value="true" unit="列" @change="change"></ux-slider>
</view>
</template> -->
<ux-text text="APP端封装的是系统的瀑布流组件, Web和小程序是自研组件, 用法和APP端保持一致"></ux-text>
</ux-card>
<ux-waterfall
ref="uxWaterfallRef"
:main-axis-gap="10"
:cross-axis-gap="10"
:padding="[10,10,10,10]"
:refresherEnabled="true"
:refresherTriggered="refresherTriggered"
:loadmoreEnabled="loadmoreEnabled"
:backtop="true"
@refresherrefresh="onRefresh"
@loadmore="onLoadmore">
<ux-waterfall-item :index="index" v-for="(item, index) in list" :key="index">
<view class="item">
<image class="img" :fade-show="true" :src="item['cover']" mode="widthFix"></image>
<text class="name">{{ item['author_name'] }}</text>
<text class="title">{{ item['title'] }}</text>
<text class="time">{{ item['published_at'] }}</text>
</view>
</ux-waterfall-item>
</ux-waterfall>
</ux-page>
</template>
ts
<script setup>
import * as plus from '@/uni_modules/ux-plus'
import { UxSliderEvent } from '@/uni_modules/ux-frame';
const title = ref('')
const col = ref(2)
const list = ref<UTSJSONObject[]>([] as UTSJSONObject[])
const refresherTriggered = ref(false)
const lastPage = ref(false)
const uxWaterfallRef = ref<UxWaterfallComponentPublicInstance | null>(null)
const loadmoreEnabled = computed((): boolean => {
return list.value.length >= 10
})
function getList(refresh: boolean) {
if(refresh) {
lastPage.value = false
refresherTriggered.value = true
}
if(list.value.length == 0) {
uni.showLoading({
title: 'loading...'
})
}
uni.request<UTSJSONObject[]>({
url: 'https://unidemo.dcloud.net.cn/api/news?column=title,author_name,cover,published_at',
method:"GET",
success: (res: RequestSuccess<UTSJSONObject[]>) => {
if (res.statusCode == 200) {
const result = res.data
if(result != null){
if(refresh) {
list.value = result
} else {
if(result.length == 0) {
lastPage.value = true
} else {
result.forEach((e: UTSJSONObject) => {
list.value.push(e)
})
}
}
}
}
},
fail: (err) => {
console.log(err);
},
complete:() => {
uni.hideLoading()
if(refresh) {
refresherTriggered.value = false
}
uxWaterfallRef.value!.loadSuccess(lastPage.value)
}
});
}
function onRefresh() {
getList(true)
}
function onLoadmore() {
getList(false)
}
function change(e: UxSliderEvent) {
col.value = e.value
}
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/waterfall.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
getList(false)
})
</script>
<script setup>
import * as plus from '@/uni_modules/ux-plus'
import { UxSliderEvent } from '@/uni_modules/ux-frame';
const title = ref('')
const col = ref(2)
const list = ref<UTSJSONObject[]>([] as UTSJSONObject[])
const refresherTriggered = ref(false)
const lastPage = ref(false)
const uxWaterfallRef = ref<UxWaterfallComponentPublicInstance | null>(null)
const loadmoreEnabled = computed((): boolean => {
return list.value.length >= 10
})
function getList(refresh: boolean) {
if(refresh) {
lastPage.value = false
refresherTriggered.value = true
}
if(list.value.length == 0) {
uni.showLoading({
title: 'loading...'
})
}
uni.request<UTSJSONObject[]>({
url: 'https://unidemo.dcloud.net.cn/api/news?column=title,author_name,cover,published_at',
method:"GET",
success: (res: RequestSuccess<UTSJSONObject[]>) => {
if (res.statusCode == 200) {
const result = res.data
if(result != null){
if(refresh) {
list.value = result
} else {
if(result.length == 0) {
lastPage.value = true
} else {
result.forEach((e: UTSJSONObject) => {
list.value.push(e)
})
}
}
}
}
},
fail: (err) => {
console.log(err);
},
complete:() => {
uni.hideLoading()
if(refresh) {
refresherTriggered.value = false
}
uxWaterfallRef.value!.loadSuccess(lastPage.value)
}
});
}
function onRefresh() {
getList(true)
}
function onLoadmore() {
getList(false)
}
function change(e: UxSliderEvent) {
col.value = e.value
}
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/waterfall.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
getList(false)
})
</script>
css
<style lang="scss">
.item {
width: 100%;
border-radius: 8px;
background-color: white;
.img {
width: 100%;
// height: 85px;
border-radius: 5px;
}
.name {
font-size: 18px;
font-weight: bold;
margin: 10px;
}
.title {
font-size: 14px;
margin: 0 10px;
color: gray;
}
.time {
font-size: 14px;
color: gray;
margin: 10px;
}
}
</style>
<style lang="scss">
.item {
width: 100%;
border-radius: 8px;
background-color: white;
.img {
width: 100%;
// height: 85px;
border-radius: 5px;
}
.name {
font-size: 18px;
font-weight: bold;
margin: 10px;
}
.title {
font-size: 14px;
margin: 0 10px;
color: gray;
}
.time {
font-size: 14px;
color: gray;
margin: 10px;
}
}
</style>