微信小程序实现分类菜单 swiper分类菜单

本文介绍如何在微信小程序中实现类似美团的滚动菜单,通过调用后台数据,结合WXML、JS和CSS实现动态分类菜单的功能。
摘要由CSDN通过智能技术生成

做项目的时候遇到仿美团上的滚动菜单,需要调用后台数据的,以下是为大家整理的
wxml

	<view class="ification">
			<swiper class="swiper" bindchange="swiperChange">
				<swiper-item class="swipers" wx:for="{
  {list}}" wx:for-item="item" wx:for-index="index" wx:key='index'>
					<view class="info" wx:for="{
  {item}}" wx:for-item="item" wx:for-index="i" catchtap="retus" wx:key='index'>
						<view class="jians">
							<text>HOT</text>
						</view>
						<view class="avatar">
							<image src="{
  {item.avatar}}"></image>
						</view>
						<view class='row'>
							<view class="title">{
  {item.name}}</view>
						</view>
					</view>
				<
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Vue 微信小程序中,可以使用 wx-swiper 实现横向滑动菜单。 1. 在页面的 .vue 文件中,添加以下代码: ```html <view class="swiper"> <swiper class="swiper-container" indicator-dots="false" autoplay="false" circular="false"> <swiper-item class="swiper-item" wx:for="{{list}}" wx:key="index"> <!-- 每个菜单项的内容 --> <view class="menu-item">{{item}}</view> </swiper-item> </swiper> </view> ``` 2. 在页面的 .vue 文件中,定义列表数据和样式: ```javascript data() { return { list: ['菜单1', '菜单2', '菜单3', '菜单4', '菜单5', '菜单6', '菜单7', '菜单8', '菜单9'], currentIndex: 0 } }, methods: { // 点击菜单项时触发 onItemClick(index) { this.currentIndex = index } } ``` ```css .swiper { height: 60rpx; overflow: hidden; } .swiper-container { height: 100%; } .swiper-item { display: flex; justify-content: center; align-items: center; height: 100%; background-color: #fff; color: #333; } .menu-item { font-size: 28rpx; padding: 10rpx 20rpx; border-bottom: 4rpx solid transparent; } .menu-item.active { border-bottom-color: #007aff; } ``` 3. 在菜单项的 view 标签中添加点击事件,并绑定 onItemClick 方法: ```html <view class="menu-item" :class="{active: currentIndex === index}" @tap="onItemClick(index)">{{item}}</view> ``` 这样就可以实现一个简单的横向滑动菜单了。当用户点击菜单项时,菜单项的样式会变成选中状态。可以根据 currentIndex 属性来判断当前选中的菜单项,从而实现相应的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值