uniapp中设置轮播图

实现:在uniapp中设置轮播图

先看效果图

 

找不到现成的接口,先在网上找几张图片,为了防链接失效,直接把图片传到文章里,文章在图就在

 

https://i-blog.csdnimg.cn/blog_migrate/99b7cd44a9e6d1d97efa2bc432fa2be2.png

 

https://i-blog.csdnimg.cn/blog_migrate/f0fa516089b8ebb7e43cd5a55080ff27.jpeg

 

https://i-blog.csdnimg.cn/blog_migrate/459a2db750fd59ca43b295a961f3b314.jpeg

帅气的图片就是这么超大张

用的是HBuilder X 3.1.7

建项目可以随便建,也可以参考这篇文章

https://blog.csdn.net/yougcave/article/details/116666640

建好后先复制上面三张大图的链接保存到index.vue的data数组swipers里

<script>
	export default {
		data() {
			return {
				swipers:[
					'https://i-blog.csdnimg.cn/blog_migrate/99b7cd44a9e6d1d97efa2bc432fa2be2.png',
					'https://i-blog.csdnimg.cn/blog_migrate/f0fa516089b8ebb7e43cd5a55080ff27.jpeg',
					'https://i-blog.csdnimg.cn/blog_migrate/459a2db750fd59ca43b295a961f3b314.jpeg',
				]
			}
		},
	}
</script>

然后在index.vue里开始写代码

uniapp有个现成的轮播图组件 swiper 而且自带了不少属性,查表就能写

<template>
	<view class="home">
		<!--circular用来设置循环轮播   indicator-dots设置下面小圆点用来点击 -->
		<swiper circular indicator-dots>
			<!-- v-for循环遍历数组 -->
			<swiper-item v-for="item in swipers" >
				<image :src="item"></image>
			</swiper-item>
		</swiper>
	</view>
</template>

最后在CSS里改下图片大小就完事了

<!-- 开启scss -->
<style lang="scss">
	.home{
		swiper{
			width: 750rpx;
			height: 470rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
	}
</style>

这个挺简单,完事,记住uniapp里有个swiper组件就好了

 

 

  • 12
    点赞
  • 59
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
Uniapp 实现卡片式轮播图,可以通过使用组件库或自定义组件来实现。以下是一个简单的实现示例: 1. 首先,在你的 Uniapp 项目引入需要的组件库,如 vant、uView 等。或者你可以自己编写一个自定义组件。 2. 在需要使用轮播图的页面,引入轮播图组件: ```vue <template> <view> <swiper class="swiper-container" indicator-dots autoplay circular> <block v-for="(item, index) in swiperList" :key="index"> <swiper-item> <!-- 卡片内容 --> <view class="card"> <image :src="item.image" mode="aspectFill" class="card-image" /> <text>{{ item.title }}</text> </view> </swiper-item> </block> </swiper> </view> </template> <script> export default { data() { return { swiperList: [ { image: '图片地址1', title: '标题1', }, { image: '图片地址2', title: '标题2', }, // 依此类推 ], }; }, }; </script> <style> .card { width: 200px; /* 设置卡片宽度 */ height: 300px; /* 设置卡片高度 */ background-color: #f5f5f5; border-radius: 8px; } .card-image { width: 100%; height: 200px; /* 设置卡片图片的高度 */ border-top-left-radius: 8px; border-top-right-radius: 8px; } </style> ``` 在上述代码,我们使用了 `swiper` 组件和 `swiper-item` 组件来实现轮播图的效果。每个 `swiper-item` 放置一个卡片内容,其使用了 `image` 组件来显示图片,`text` 组件来显示标题。 你可以根据实际需求调整卡片的样式和轮播图的配置,例如设置自动轮播、指示器等。同时,也可以根据项目需要自定义组件样式和交互效果。 希望这个示例能够帮助到你!
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

youngcave2

等待第一笔打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值