uni-app:循环数据点击事件获取每行指定数据(获取参数)

效果

页面样式

点击首行控制台输出信息

代码

:data-id="item.id":定义id信息,在点击事件时e.currentTarget.dataset.id获取点击行的id

:data-index="index":定义index信息,在点击事件时e.currentTarget.dataset.index获取点击行的索引

:data-item="item":定义item信息,在点击事件时e.currentTarget.dataset.item获取点击行的整行信息

html 复制代码
<template>
	<view>
		<view class="item_all" v-for="(item, index) in allinfo" :key="index">
			<view class='position' :data-id="item.id" :data-index="index" :data-item="item" @tap="deatil">
				<view class="vv_1">id: {{item.id}}</view>
				<view class="vv_1">name: {{item.name}}</view>
				<view class="vv_1">age: {{item.age}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				allinfo: [{
						id: 1,
						name: '张三',
						age: '12'
					},
					{
						id: 2,
						name: '李四',
						age: '21'
					},
					{
						id: 3,
						name: '王五',
						age: '44'
					},
				]
			};
		},
		methods: {
			deatil(e) {
				console.log("id:"+e.currentTarget.dataset.id)//获取行id信息
				console.log("index:"+e.currentTarget.dataset.index)//获取索引index信息
				console.log(e.currentTarget.dataset.item)//获取整行信息
			}
		}
	};
</script>
<style>
	.item_all {
		margin-bottom: 3%;
	}

	.position {
		padding: 6% 0;
		width: 100%;
		background-color: #fff;
		box-shadow: 4rpx 4rpx 4rpx gainsboro;
	}

	.vv_1 {
		margin: 0 5%;
		word-break: break-all;
	}
</style>
相关推荐
尾善爱看海20 小时前
不常用的浏览器 API —— Web Speech
前端
美酒没故事°20 小时前
vue3拖拽+粘贴的综合上传器
前端·javascript·typescript
jingling55521 小时前
css进阶 | 实现罐子中的水流搅拌效果
前端·css
悟能不能悟1 天前
前端上载文件时,上载多个文件,但是一个一个调用接口,怎么实现
前端
可问春风_ren1 天前
前端文件上传详细解析
前端·ecmascript·reactjs·js
羊小猪~~1 天前
【QT】--文件操作
前端·数据库·c++·后端·qt·qt6.3
晚风资源组1 天前
CSS文字和图片在容器内垂直居中的简单方法
前端·css·css3
Miketutu1 天前
Flutter学习 - 组件通信与网络请求Dio
开发语言·前端·javascript
摘星编程1 天前
React Native for OpenHarmony 实战:Swiper 滑动组件详解
javascript·react native·react.js
鸣弦artha1 天前
Flutter框架跨平台鸿蒙开发——Build流程深度解析
开发语言·javascript·flutter