当前位置: 首页 > article >正文

uniapp开发,轮播图,文字省略号,具名插槽的实现

轮播图的实现

uniapp官网—->组件--->内置组件----->swiper

<view class="banner">
			<swiper circular  indicator-dots="true" indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff" autoplay>
				<swiper-item >
					<image src="../../common/images/banner1.jpg" mode="aspectFill"></image>
				</swiper-item>
				<swiper-item >
					<image src="../../common/images/banner2.jpg"  mode="aspectFill"></image>
				</swiper-item>
				<swiper-item >
					<image src="../../common/images/banner3.jpg"  mode="aspectFill"></image>
				</swiper-item>
			</swiper>
</view>

style样式     swiper-item的样式写为&-item

.banner{
			width: 750rpx;
			padding: 30rpx 0;
			swiper{
				width: 750rpx;
				height: 340rpx;
				&-item{
					width: 100%;
					height: 100%;
					padding: 0 30rpx;
					image{
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
				}
			}

文字省略号

文字块垂直滚动+文字块省略号

<view class="center">
				<swiper vertical autoplay interval="1500" duration="300" circular>
					<!-- 省略号布局 -->
					<swiper-item v-for="item in 4">文字内容文字内容文字内容文字内容文字内容文字内容文字内容</swiper-item>
				</swiper>
</view>

重点是style样式  

overflow:hidden;   white-space:nowrap;     text-overflow:ellipsis;

        swiper{
					height: 100%;
					&-item{
						height: 100%;
						font-size: 30rpx;
						letter-spacing: 4rpx;
						color: #666;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}

组件具名插槽定义公共标题模块

具名插槽的使用场景,下面图片中箭头所指的两个模块军可以用同一模块实现

具体实现步骤 

第一步创建vue文件

文件内容    common-title.vue文件

<template>
	<view class="common-title">
		<view class="name">
			<slot name="name"></slot>
		</view>
		<view class="custom">
			<slot name="custom"></slot>
		</view>
	</view>
</template>

<script setup>
	
	
</script>

<style lang="scss" scoped>
.common-title{
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0 30rpx;
}
</style>

 引用common-title.vue的文件内容

<view class="select">
			<common-title>
				<!-- 具名插槽 -->
				<!-- 每日推荐 -->
				<template #name>每日推荐</template>
				<template #custom>
					<uni-icons type="calendar" size="18" color="#28b389"></uni-icons>
					<uni-dateformat :date="Date.now()"></uni-dateformat>
				</template>
			</common-title>
</view>
<!-- 专题精选 -->
<view class="theme">
			<common-title>
				<!-- 具名插槽 -->
				<template #name>专题精选</template>
				<template #custom>More+</template>
			</common-title>
</view>


http://www.kler.cn/a/561006.html

相关文章:

  • springboot实现文件上传到华为云的obs
  • 前端面试题---vue和react的区别
  • Ubuntu及其衍生系统安装Python
  • VMware17.6+CentOS 8安装教程
  • C++核心指导原则: 错误处理
  • AWS S3深度解析:十大核心应用场景与高可用架构设计实践
  • Pretraining Language Models with Text-Attributed Heterogeneous Graphs
  • kotlin 知识点五 泛型和委托
  • Kafka集群性能测试实战指南:从规划到验证,全面掌握高效测试方案
  • 《2025国内免费DeepSeek-R1自部署平台实测指南:三大运营商/腾讯/华为哪家强?附避坑清单》
  • python学智能算法(四)|遗传算法:原理认识和极大值分析
  • 注意力机制在 Transformer 模型中的核心作用剖析
  • Docker下的Elastic search
  • 无前端经验如何快速搭建游戏站:使用 windsurf 从零到上线的详细指南
  • 机器学习数学基础:34.点二列
  • Vue3中watchEffect、watchPostEffect、watchSyncEffect的区别
  • 在LangFlow中集成OpenAI Compatible API类型的大语言模型
  • DeepSeek开源周高能开场:新一代高效推理引擎FlashMLA正式发布
  • EX_25/2/22
  • 115 道 MySQL 面试题,从简单到深入!