uniapp自定义卡片轮播图

效果图

1、封装组件

<template>
	<view>

		<!-- 自定义卡片轮播 -->
		<swiper class="swiperBox" :previous-margin="swiper.margin" :next-margin='swiper.margin' :circular="true"
			@change="swiperChange">
			<swiper-item class="swiperItem" v-for="(item,index) in swiper.list" :key="index">
				<view class="swiperWrap" :class="{'active':swiper.index == index}">
					<view class="swiperPic">
						<image :src="item.url"></image>
					</view>
					<view class="swiperCon">
						<view class="swiperName">{{item.title}}</view>
						<view class="swiperPrice">
							<view class="group">
								<image src="/static/index/swiperGroup.png" mode="aspectFill"></image>
							</view>
							<view class="price">
								¥<text>{{item.price}}</text>
							</view>
						</view>
					</view>
				</view>
			</swiper-item>
		</swiper>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiper: {
					margin: "150rpx",
					index: 0,
					list: [{
						url: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
						title: '谁念西风独自凉',
						price: '0.01',
					}, {
						url: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
						title: '沉思往事立残阳',
						price: '0.02',
					}, {
						url: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
						title: '沉思往事立残阳',
						price: '0.03',
					}]
				},
			}
		},
		components: {

		},
		mounted() {

		},
		methods: {
			//swiper滑动事件
			swiperChange(e) {
				this.swiper.index = e.detail.current;
			},
		}
	}
</script>

<style scoped lang="scss">
	.swiperBox {
		height: 500rpx;
		overflow: hidden;
	}

	.swiperItem {
		border-radius: 20rpx;
		overflow: hidden;
	}

	.swiperWrap {
		transform: scale(0.9);
		transition: transform 0.3s ease-in-out 0s;
	}

	.swiperWrap.active {
		transform: scale(1);
	}

	.swiperPic {
		width: 100%;
		height: 325rpx;
	}

	.swiperPic image {
		width: 100%;
		height: 100%;
	}

	.swiperCon {
		padding: 20rpx;
		background-color: #fff;
	}

	.swiperName {
		font-size: 32rpx;
		font-weight: bold;
		text-align: center;
	}

	.swiperPrice {
		width: 160rpx;
		height: 54rpx;
		border-radius: 28rpx;
		border: 2rpx solid $uni-theme;
		overflow: hidden;
		margin: 20rpx auto 0;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.group {
		width: 60rpx;
		height: 54rpx;
		background: $uni-theme;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.group image {
		width: 28rpx;
		height: 28rpx;
	}

	.price {
		width: 100rpx;
		height: 54rpx;
		font-size: 24rpx;
		color: $uni-theme;
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.price text {
		font-size: 32rpx;
	}
</style>

2、组件引用

<template>
	<view>

        <swiperCard></swiperCard>

	</view>
</template>

<script>
	import swiperCard from "@/components/swiperCard/swiperCard"

	export default {
		components: {
			swiperCard
		},
		data() {
			return {
				
			}
		},

	}
</script>

相关推荐

  1. Swiper

    2024-04-04 20:20:01       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-04 20:20:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-04 20:20:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-04 20:20:01       82 阅读
  4. Python语言-面向对象

    2024-04-04 20:20:01       91 阅读

热门阅读

  1. Spark安全日志分析与事件调查:实战指南

    2024-04-04 20:20:01       38 阅读
  2. Qt工具中的lrelease.exe处理.ts文件

    2024-04-04 20:20:01       40 阅读
  3. 简单易懂的SQL添加数据教程

    2024-04-04 20:20:01       37 阅读
  4. kkksc03考前临时抱佛脚(01背包问题)

    2024-04-04 20:20:01       36 阅读
  5. golang dlv: could not find statement

    2024-04-04 20:20:01       33 阅读
  6. Go语言如何处理整数溢出

    2024-04-04 20:20:01       41 阅读
  7. DLC原理解析及其优化思考

    2024-04-04 20:20:01       33 阅读
  8. Ubuntu下使用Caddy安装部署LXD

    2024-04-04 20:20:01       39 阅读
  9. 区块链技术的基本概念学习

    2024-04-04 20:20:01       35 阅读
  10. vue3从精通到入门11:高级侦听器watchEffect

    2024-04-04 20:20:01       43 阅读