uniapp列表实现方式 v-for

创建列表视图 v-for

v-for="对象item in 数组"

v-for="(对象item,下标) in 数组"

v-for="(对象item,使用这个键取到的值,下标) in 数组"

:key 绑定标识 一般建议使用对象中的id等值 类型 any

html 复制代码
<template>
	<view>
		<view class="line" v-for="item in list" :key="item.title" @click="itemClick(key)">
			<image class="imageStype" src="../../static/logo.png"></image>
			<text class="textHellow">{{item.title}}</text>
		</view>
		<view class="line" v-for="(item,i) in list" :key="i" @click="itemClick(key)">
			<image class="imageStype" src="../../static/logo.png"></image>
			<text class="textHellow">{{item.title}}</text>
		</view>
		<view class="line" v-for="(item,title,i) in list" :key="i" @click="itemClick(key)">
			<image class="imageStype" src="../../static/logo.png"></image>
			<text class="textHellow">{{title}}</text>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [{
					title: 0
				}, {
					title: 1
				}, {
					title: 2
				}]

			}
		},
		methods: {
			itemClick(ii) {
				// setInterval(() => {
				// 	Array.from(this.list).forEach((item)=>{
				// 		item.title +=1 
				// 	})
				// }, 2000)
				setTimeout(() => {
					Array.from(this.list).forEach((item) => {
						item.title += 1
					})
				}, 2000)
			}
		},
		beforeDestroy() {

		}
	}
</script>

<style>
	.imageStype {
		width: 120rpx;
		height: 120rpx;
		margin-left: 40rpx;

	}

	.line {
		margin-top: 20rpx;
		display: flex;
		flex-direction: row;
		padding-top: 40rpx;
		padding-bottom: 40rpx;
		width: 670rpx;
		margin-left: 40rpx;
		border: 2rpx solid gray;
		border-radius: 16rpx;
		background-color: aliceblue;
		box-shadow: 8rpx 8rpx 4rpx 0 gray;
	}

	.textHellow {
		margin-left: 20rpx;
		font-weight: bold;
		font-size: 32rpx;
	}
</style>
		
相关推荐
tachibana27 小时前
Go 语言里的 Context 是什么?
开发语言·后端·golang·go·语言
天桥下的卖艺者7 小时前
R语言使用ggcube包轻松绘制文章中的各类3D图形
开发语言·3d·r语言
唐钰小宝B8 小时前
深度解读 JDK 8、JDK 11、JDK 17 和 JDK 21 的区别
java·开发语言·windows
const_qiu8 小时前
第二章 2.6:初始化 NestJS 服务端 —— TypeScript 后端框架体验
前端·javascript·typescript
知识分享小能手9 小时前
C学习教程,从入门到精通,C语言指针 —— 详细知识点总结(10)
c语言·开发语言·学习
熊猫钓鱼>_>9 小时前
开源鸿蒙平台 KMP 三方库 kotlin-csv 适配全流程:从编码假设到沙箱真机互通验证
开发语言·人工智能·华为·kotlin·harmonyos·鸿蒙
张张123y9 小时前
# 后端第七课:FastAPI 实战入门(用刚学的 Python 写第一个 API 接口)
开发语言·python·mysql·api·fastapi
miofly9 小时前
GitHub 今日推荐|sweety-handdraw-video:文章转手绘口播视频
javascript·开源·github
小陈不好吃9 小时前
Java 泛型与类型擦除:从 PECS 原则到 TypeToken 绕过
java·开发语言·windows·pecs 原则·typetoken绕过
Shaoshing10 小时前
存储引擎与架构
java·开发语言·架构