Skip to content
本页导读

Sticky-section

组件类型:UxStickySectionComponentPublicInstance

平台兼容性

UniApp X

AndroidiOSweb鸿蒙 Next小程序
x

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxx

Props

属性名类型默认值说明
sectionIdStringid
typeString类型,如果一个页面有多个本组件,可设置type区分
indexNumber下标
pushPinnedHeaderBooleantruesticky-section元素重叠时是否继续上推
paddingNumber[]长度为4的数组,按top、right、bottom、left顺序指定内边距

示例代码

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-scroll
			ref="uxScrollRef"
			:refresherEnabled="true" 
			:refresherTriggered="refresherTriggered" 
			:loadmoreEnabled="loadmoreEnabled" 
			:backtop="true"
			@refresherrefresh="onRefresh"
			@loadmore="onLoadmore">
			
			<ux-card direction="column" icon="flag-filled" title="Scroll列表" :bold="true">
				<ux-text text="扩展支持自定义下拉刷新、上拉加载自定义样式,可显示返回顶部按钮"></ux-text>
			</ux-card>
			
			<ux-card v-for="(item, index) in list" :key="index">
				<ux-row :flex="true">
					<ux-image :radius="5" :src="item['cover']"></ux-image>
					<ux-col :ml="10">
						<ux-text :bold="true" :size="15" :text="item['author_name']"></ux-text>
						<ux-text :text="item['title']"></ux-text>
						<ux-text :text="item['published_at']"></ux-text>
					</ux-col>
				</ux-row>
			</ux-card>
		</ux-scroll>
	</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-scroll
			ref="uxScrollRef"
			:refresherEnabled="true" 
			:refresherTriggered="refresherTriggered" 
			:loadmoreEnabled="loadmoreEnabled" 
			:backtop="true"
			@refresherrefresh="onRefresh"
			@loadmore="onLoadmore">
			
			<ux-card direction="column" icon="flag-filled" title="Scroll列表" :bold="true">
				<ux-text text="扩展支持自定义下拉刷新、上拉加载自定义样式,可显示返回顶部按钮"></ux-text>
			</ux-card>
			
			<ux-card v-for="(item, index) in list" :key="index">
				<ux-row :flex="true">
					<ux-image :radius="5" :src="item['cover']"></ux-image>
					<ux-col :ml="10">
						<ux-text :bold="true" :size="15" :text="item['author_name']"></ux-text>
						<ux-text :text="item['title']"></ux-text>
						<ux-text :text="item['published_at']"></ux-text>
					</ux-col>
				</ux-row>
			</ux-card>
		</ux-scroll>
	</ux-page>
</template>
ts
<script setup>
	
	
	import * as plus from '@/uni_modules/ux-plus'
	
	const title = ref('')
	const list = ref<UTSJSONObject[]>([] as UTSJSONObject[])
	const refresherTriggered = ref(false)
	const lastPage = ref(false)
	
	const uxScrollRef = ref<UxScrollComponentPublicInstance | 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) => {
				if (res.statusCode == 200) {
					const result = res.data
					
					if(result != null){
						if(refresh) {
							list.value = result
						} else {
							if(list.value.length > 50) {
								lastPage.value = true
							} else {
								list.value = list.value.concat(result)
							}
						}
					}
				}
			},
			complete:() => {
				uni.hideLoading()
				
				if(refresh) {
					refresherTriggered.value = false
				}
				
				uxScrollRef.value!.loadSuccess(lastPage.value)
			}
		});
	}
	
	function onRefresh() {
		getList(true)
	}
	
	function onLoadmore() {
		getList(false)
	}
	
	const showDoc = ref(false)
	
	function onDoc() {
		plus.openWeb({
			title: '在线文档',
			url: 'https://www.uxframe.cn/component/scroll.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'
	
	const title = ref('')
	const list = ref<UTSJSONObject[]>([] as UTSJSONObject[])
	const refresherTriggered = ref(false)
	const lastPage = ref(false)
	
	const uxScrollRef = ref<UxScrollComponentPublicInstance | 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) => {
				if (res.statusCode == 200) {
					const result = res.data
					
					if(result != null){
						if(refresh) {
							list.value = result
						} else {
							if(list.value.length > 50) {
								lastPage.value = true
							} else {
								list.value = list.value.concat(result)
							}
						}
					}
				}
			},
			complete:() => {
				uni.hideLoading()
				
				if(refresh) {
					refresherTriggered.value = false
				}
				
				uxScrollRef.value!.loadSuccess(lastPage.value)
			}
		});
	}
	
	function onRefresh() {
		getList(true)
	}
	
	function onLoadmore() {
		getList(false)
	}
	
	const showDoc = ref(false)
	
	function onDoc() {
		plus.openWeb({
			title: '在线文档',
			url: 'https://www.uxframe.cn/component/scroll.html',
			// blur: 1,
			success: () => {
				showDoc.value = true
			},
			complete: () => {
				showDoc.value = false
			}
		})
	}
	
	onLoad((e) => {
		title.value = e['title'] ?? ''
		
		getList(false)
	})
</script>
css
<style lang="scss">
	
</style>
<style lang="scss">
	
</style>