mpvue小程序轮播图绑定动态点击事件

文采不佳,话不多说。分享一个mpvue小程序轮播图绑定动态点击跳转页面,这个源码可以直接引用。用微信原生的轮播图也可,不过由于设计稿需要,我才改写了指示点的样式。

<template>
	<div>
		<swiper class="swiper" autoplay="true" interval="1000" duration="1000" circular easing-function="easeInOutCubic"   @change="switchItem('switchItem',$event)"
		 :current="currentTab">
			<block v-for="(item, index) in images" :index="index" :key="index">
				<a :href="item.url">
					<swiper-item>
						<img :src="item.imgurl" class="slide-image" mode="widthFix" />
					</swiper-item>
				</a>				
			</block>
		</swiper>
		<div class="tab">
			<a :class="currentTab=='0'?'nav active': 'nav'" data-current="0" @click="switchTab('switchTab',$event)"></a>
			<a :class="currentTab=='1'?'nav active': 'nav'" data-current="1" @click="switchTab('switchTab',$event)"></a>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				currentTab: "0",
				images: [{
						imgurl: require("../../../static/images/banner1.png"),
						url:"../counter/main"
					},
					{
						imgurl: require("../../../static/images/banner.png"),
						url:"../logs/main"
					}
				]
			}
		},
		components: {},
		methods: {
			switchTab: function(prompt, res) {
				// console.log(prompt,res);
				let oIndex = res.mp.currentTarget.dataset.current;
				this.currentTab = oIndex;
			},
			switchItem: function(prompt, res) {
				// console.log(prompt,res.mp.detail.current);
				let oIndex = res.mp.detail.current;
				this.currentTab = oIndex;
			}
		},
	}
</script>

<style scoped>
	.swiper{
		padding: 0 30rpx 0 30rpx;
		width: 690rpx;
		height: 280rpx;
	}
	.swiper img{
		width: 690rpx;
		height: 280rpx;
	}
	.tab {
		width: 100%;
		padding-top: 10rpx;
		display: flex;
		justify-content: center;
	}
	.nav {
		width: 80rpx;
		height: 6rpx;
		background: #CCCCCC;
		border-radius: 3rpx;
	}

	.nav.active {
		background: rgba(51, 51, 51, 1);
	}
</style>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值