Skip to content
本页导读

Waterfall

组件类型:UxWaterfallComponentPublicInstance

支持配置间距,自动计算子项高度,支持子项自定义高度

平台兼容性

UniApp X

AndroidiOSweb鸿蒙 Next小程序
x

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxx

Props

属性名类型默认值说明
defaultSlot默认slot
refresherSlotrefresherslot
loadmoreSlotloadmoreslot
backtopSlotbacktopslot
crossAxisCountNumber2交叉轴元素数量
mainAxisGapNumber0主轴方向间隔
crossAxisGapNumber0交叉轴方向间隔
paddingArray[0,0,0,0]长度为4的数组,按top、right、bottom、left顺序指定内边距
associativeContainerString关联的滚动容器
bouncesBooleantrue控制是否回弹效果
upperThresholdNumber50距顶部/左边多远时(单位px),触发scrolltoupper事件
lowerThresholdNumber50距底部/右边多远时(单位px),触发scrolltolower事件
scrollTopNumber0设置竖向滚动条位置
scrollIntoViewString值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素
scrollWithAnimationBooleantrue是否在设置滚动条位置时使用滚动动画,设置false没有滚动动画
refresherEnabledBooleanfalse开启下拉刷新
refresherThresholdNumber45设置下拉刷新阈值
refresherMaxDragDistanceNumber80设置下拉最大拖拽距离(单位px)
refresherBackgroundStringtransparent设置下拉刷新区域背景颜色
refresherTriggeredBooleanfalse设置当前下拉刷新状态,true表示下拉刷新已经被触发,false表示下拉刷新未被触发
refresherStatesArray下拉刷新状态文案
loadmoreEnabledBooleanfalse开启上拉加载
loadmoreStatesArray上拉加载状态文案
showScrollbarBooleanfalse控制是否出现滚动条
customNestedScrollBooleanfalse子元素是否开启嵌套滚动将滚动事件与父元素协商处理
disabledBooleanfalse禁止滚动
backgroundStringtransparent背景颜色
xstyleArray自定义样式

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>