好看的uniapp列表
设计美观的UniApp列表
使用uni-list组件可以快速创建基础列表样式,搭配uni-icons和自定义样式提升视觉效果。示例代码:
<template>
<uni-list>
<uni-list-item
v-for="(item, index) in list"
:key="index"
:title="item.title"
:note="item.desc"
clickable
@click="handleClick(item)"
>
<template v-slot:header>
<uni-icons type="contact" size="24"></uni-icons>
</template>
</uni-list-item>
</uni-list>
</template>
卡片式列表布局
通过view和CSS阴影效果实现卡片式设计,适合商品展示等场景:
<template>
<view class="card-list">
<view
v-for="(item, index) in list"
:key="index"
class="card-item"
@click="handleClick(item)"
>
<image :src="item.image" mode="aspectFill"></image>
<text class="title">{{item.title}}</text>
<text class="price">¥{{item.price}}</text>
</view>
</view>
</template>
<style>
.card-list {
display: flex;
flex-wrap: wrap;
padding: 10px;
}
.card-item {
width: 48%;
margin: 1%;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
overflow: hidden;
}
</style>
瀑布流布局实现
结合CSS多列布局实现瀑布流效果,适合图片类内容展示:
<template>
<view class="waterfall">
<view
v-for="(item, index) in list"
:key="index"
class="item"
:style="{height: item.height + 'px'}"
>
<image :src="item.image"></image>
<text>{{item.title}}</text>
</view>
</view>
</template>
<style>
.waterfall {
column-count: 2;
column-gap: 10px;
padding: 10px;
}
.item {
break-inside: avoid;
margin-bottom: 10px;
}
</style>
交互增强列表
添加滑动操作、加载动画等交互效果:
<template>
<uni-swipe-action>
<uni-swipe-action-item
v-for="(item, index) in list"
:key="index"
:right-options="options"
>
<uni-list-item
:title="item.title"
showArrow
/>
</uni-swipe-action-item>
</uni-swipe-action>
</template>
性能优化技巧
对于长列表使用uni-virtual-list虚拟滚动:
<template>
<uni-virtual-list
:list="bigData"
:height="800"
:itemSize="100"
>
<template v-slot:default="{item}">
<view class="item">{{item.text}}</view>
</template>
</uni-virtual-list>
</template>
主题适配方案
通过CSS变量实现暗黑模式切换:
.list-item {
background: var(--bg-color);
color: var(--text-color);
}
:root {
--bg-color: #ffffff;
--text-color: #333333;
}
.dark {
--bg-color: #1a1a1a;
--text-color: #f0f0f0;
}






