用uniapp开发一段卡片轮播图的微信小程序代码
时间: 2024-01-01 17:06:00 浏览: 327
好的,以下是一份使用uniapp框架开发的微信小程序卡片轮播图代码示例:
```html
<template>
<view class="swiper-container">
<swiper class="swiper-wrapper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration">
<block v-for="(item, index) in cardList" :key="index">
<swiper-item class="swiper-slide">
<view class="card">
<image class="card-img" :src="item.imageUrl"></image>
<view class="card-content">{{item.content}}</view>
</view>
</swiper-item>
</block>
</swiper>
</view>
</template>
<script>
export default {
data() {
return {
indicatorDots: true,
autoplay: true,
interval: 5000,
duration: 1000,
cardList: [
{
imageUrl: 'https://example.com/card1.jpg',
content: '这是卡片1的内容'
},
{
imageUrl: 'https://example.com/card2.jpg',
content: '这是卡片2的内容'
},
{
imageUrl: 'https://example.com/card3.jpg',
content: '这是卡片3的内容'
}
]
}
}
}
</script>
<style>
.swiper-container {
height: 200rpx;
width: 100%;
}
.swiper-slide {
display: flex;
justify-content: center;
}
.card {
width: 90%;
height: 150rpx;
background-color: #fff;
border-radius: 10rpx;
box-shadow: 0 2rpx 6rpx rgba(0,0,0,0.2);
display: flex;
flex-direction: column;
justify-content: flex-end;
padding: 20rpx;
margin-bottom: 20rpx;
}
.card-img {
width: 100%;
height: 80%;
border-radius: 10rpx;
object-fit: cover;
margin-bottom: 10rpx;
}
.card-content {
font-size: 28rpx;
color: #333;
}
</style>
```
这份代码与前面微信小程序的代码类似,只是使用了uniapp框架进行开发,并且在模板中使用了vue语法。需要注意的是,uniapp中的Swiper组件与微信小程序的Swiper组件略有不同,具体使用方式可以参考uniapp官方文档。
阅读全文
相关推荐














