微信小程序或 uni-app 的 swiper 组件的自定义指示点,可以在轮播图外显示指示点,样式自定义

自定义指示点组件

// swiperDot.vue

<template>
	<view class="dot-main">
		<view :class="['dot-item',current==index?'active':'']" v-for="(item,index) in list" :key="index"></view>
	</view>
</template>
<style>
	.dot-main {
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.dot-item {
		width: 10.41rpx;
		height: 10.41rpx;
		border-radius: 50%;
		background-color: rgba(255,255,255,0.5);
		margin: 0 6upx;
		box-sizing: border-box;
	}
	.active {
		border-radius: 33.33rpx;
		width: 25rpx;
		background-color: #FFFFFF;
	}
</style>
<script>
	export default {
		props: [ 'list','current'],
		data() {
			return {
				
			};
		}
	}
</script>

使用方式:

<template>
	<view class="content">
		<swiper class="swiper-box" @change="change">
			<swiper-item v-for="(item, index) in list" :key="index">
				<view class="swiper-item">{{ item.content }}</view>
			</swiper-item>
		</swiper>
		<swiper-dot class="dot" :current="current" :list="list"></swiper-dot>
	</view>
</template>

<script>
import swiperDot from '@/components/swiperDot/swiperDot.vue';
export default {
	components: { swiperDot },
	data() {
		return {
			list: [
				{
					content: '内容 A'
				},
				{
					content: '内容 B'
				},
				{
					content: '内容 C'
				}
			],
			current: 0
		};
	},
	onLoad() {},
	methods: {
		change(e) {
			this.current = e.detail.current;
		}
	}
};
</script>

<style>
.content {
	position: relative;
}
.dot {
	position: absolute;
	bottom: 10px;
	right: 10px;
}
.swiper-box {
	background-color: #808080;
	width: 750rpx;
	height: 300rpx;
}
</style>

Tips:

  • 指示点的样式可以根据自己需求修改
  • swiper-item 尽量控制在一定数量之内,否则指示点可能会超出屏幕
  • 9
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值