Skip to content
# t-list-item

ListItem 列表项

t-list-item 组件介绍 ​

长列表子组件,list-view组件的唯一合法子组件。每个item是一行兼容性。

t-list-item 平台兼容 ​

HarmonyH5AndroidiOS小程序UTS
✅✅✅✅✅✅

t-list-item 基础用法 ​

vue
<template>
	<view :class="[`p-15 f tpg`]">
		<tui-theme-switch></tui-theme-switch>
		<t-card class='mb-15'
				title="List 滚动视图"
				sub-title="对官方list-view组件的增强,增加自定义下拉刷新和上拉加载,增加WEB端和IOS端支持【scrollend】事件"></t-card>
		<t-list type="primary"
				class="f"
				ref="ins"
				@scrolltolower="scrolltolower"
				@refresherrefresh="refresherrefresh"
				@scrollend="scrollend">
			<t-list-item v-for='(item,index) in componentList'
						 :key="index">
				<t-row :class="`p-15 mb-15 tvg trm fjcb`">
					<text :class="[`ttc-`]">{{item['name']}}</text>
					<t-icon name="thumb-up"></t-icon>
					<t-icon name="edit-pen"></t-icon>
					<t-icon name="star"></t-icon>
					<t-icon name="trash"></t-icon>
				</t-row>
			</t-list-item>
		</t-list>
	</view>
</template>

<script setup>
	import { TuiApi } from '@/api'
	import { TuiSleep } from '@/uni_modules/tui-common'
	const ins = ref<TListComponentPublicInstance | null>(null)
	const mask = ref(true)
	const cur = ref(1)
	const total = ref(0)
	const pageSize = ref(20)
	const list = ref<UTSJSONObject[]>([])
	const componentList = ref<UTSJSONObject[]>([])
	const sleep = new TuiSleep(1000)
	let loading : boolean = false
	function getComponentList() : Promise<UTSJSONObject[]> {
		return new Promise((
			resolve : (rst : UTSJSONObject[]) => void
		) => {
			if (loading) return
			loading = true
			TuiApi('getComponentTest', {
				"current": cur.value,
				"pageSize": pageSize.value,
				"keyword": '',
				"type": 'all',
				devstatus: 'completed'
			}, true).then((res : UTSJSONObject) => {
				const lastPage = (res as UTSJSONObject).getBoolean('data.lastPage')!
				sleep.call(() => {
					cur.value++
					loading = false
					if (lastPage) {
						ins.value!.setLoadmore(3)
					} else {
						//设置状态为0会销毁组件,避免loading会在后台运行
						ins.value!.setLoadmore(0)
					}
					nextTick(() => {
						resolve((res as UTSJSONObject).getArray('data.list') as UTSJSONObject[])
					})
				})
			})
		})
	}
	function scrollend(e : UniScrollEvent) {
		console.log(e)
	}
	function refresherrefresh() {
		loading = false
		cur.value = 1
		getComponentList().then((data : UTSJSONObject[]) => {
			componentList.value = data
			ins.value!.closerefresher()
		})
	}
	function scrolltolower() {
		getComponentList().then((data : UTSJSONObject[]) => {
			componentList.value.push(...data)
		})
	}
	onUnload(() => {
		sleep.clear()
	})
	onLoad(() => {
		getComponentList().then((data : UTSJSONObject[]) => {
			ins.value!.hideMask()
			componentList.value = data
		})
	})
</script>

t-list-item Props ​

属性名类型默认值说明可选值
sizeString""组件尺寸large, medium, small, mini
typeString""组件类型info, primary, error, warning, success
disabledBooleanfalse组件是否禁用true, false
hoverBooleanfalse是否有点击效果true, false
pathString""点击组件后跳转的页面路径-
effectString""组件显示主题normal, dark, light, plain

t-list-item Events ​

事件名说明回调参数
click点击时触发UniPointerEvent

t-list-item Slots ​

插槽名说明
default内容插槽,用于放置列表项的内容