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>