04 首页swiper部分

1. 完成效果图

在这里插入图片描述

2.新建IndexSwiper.vue文件

新建IndexSwiper.vue文件目录结构如图:
在这里插入图片描述
新建IndexSwiper.vue代码如下

<template>
	<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
		<swiper-item>
			<view class="swiper-item">
				<image class='swiper-img' src="../../static/img/swiper1.jpg" mode=""></image>
			</view>
		</swiper-item>
		<swiper-item>
			<view class="swiper-item">
				<image class='swiper-img' src="../../static/img/swiper2.jpg" mode=""></image>
			</view>
		</swiper-item>
		<swiper-item>
			<view class="swiper-item">
				<image class='swiper-img' src="../../static/img/swiper3.jpg" mode=""></image>
			</view>
		</swiper-item>
	</swiper>
</template>

<script>
</script>

<style scoped>
swiper{
	width:100%;
	height: 400rpx;
}
.swiper-img{
	width:100%;
	height: 400rpx;
}	
</style>

在pages/index/index.vue中引入IndexSwiper组件代码如下:

<template>
	<view class='index'>
		
		<IndexSwiper></IndexSwiper>
		
	</view>
</template>

<script>
	import IndexSwiper from '@/components/index/IndexSwiper.vue'
	export default {
		data() {
			return {
			
			}
		},
		components:{
			IndexSwiper
		},
		onLoad() {

		},
		methods: {

		}
	}
</script>

<style scoped>

</style>

3. swiper的坑

swiper的坑总结:

  1. 组件名称swiper.vue 或者 Swiper.vue , 在传递数据的时候有可能图片就不见了。
  2. 改变图片的大小咱们要用rpx的单位。
  3. 本身swiper是有150px的默认高度,app中需要改变默认高度需要加入:
    swiper{
    		width:100%;
    		height:400rpx;
    	}
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值