scroll-view 横向移动到对应id位置

<template>
	<view>
		<view>
			<scroll-view class="menu" :scroll-into-view="goIndex" scroll-x="true">
				<view class="menu-view">
					<view v-for="(item,index) in list" :id='"id" + index' @tap="scrollTurn(index,item.id)" class="menu-item" :class="item.id==selectId?'active':''">
						<view class="name">{{item.name}}</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selectId: 0,
				goIndex: "",
				list: [{
						name: "啊啊啊",
						id: 0
					},
					{
						name: "不不不",
						id: 1
					},
					{
						name: "吵吵吵",
						id: 2
					},
					{
						name: "对对对",
						id: 3
					},
					{
						name: "呃呃呃",
						id: 4
					},
					{
						name: "烦烦烦",
						id: 5
					},
					{
						name: "嘎嘎嘎",
						id: 6
					},
					{
						name: "哈哈哈",
						id: 7
					},
					{
						name: "急急急",
						id: 8
					},
					{
						name: "酷酷酷",
						id: 9
					},
					{
						name: "啦啦啦",
						id: 10
					},
					{
						name: "喵喵喵",
						id: 11
					},
					{
						name: "你你你",
						id: 12
					}
				]
			}
		},
		methods: {
			scrollTurn(index, id) {
				this.goIndex = "id" + index;
				this.selectId = id;
			}
		}
	}
</script>

<style>
	.menu {
		width: 100%;
		height: 50rpx;
		display: flex;
	}

	.menu-view {
		display: flex;
		flex-wrap: nowrap;
	}

	.menu-item {
		font-size: 24rpx;
		margin-left: 60rpx;
	}

	.menu-item .name {
		width: 100rpx;
		height: 40rpx;
		line-height: 40rpx;
		text-align: center;
	}

	.active {
		background-color: #1779FE;
		color: #fff;
		border-radius: 10rpx;
	}
</style>

scroll-into-view值应为某子元素id(id不能以数字开头)会报错t.group is not a function

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值