前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mpvue小程序轮播图绑定动态点击事件

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

作者头像
全栈程序员站长
发布2022-08-31 18:06:12
1.1K0
发布2022-08-31 18:06:12
举报

大家好,又见面了,我是你们的朋友全栈君。

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

代码语言:javascript
复制
<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>

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/143651.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年5月2,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云开发 CloudBase
云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档