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>
		
相关推荐
前端Hardy4 分钟前
别再乱写正则了!一行 regex 可能让你的网站瘫痪 10 分钟
前端·javascript·面试
摸鱼的春哥1 小时前
【实战】吃透龙虾🦞,你写的Agent也能支持Skills渐进式披露
前端·javascript·后端
孟祥_成都1 小时前
用 AI,0 基础复刻网页顶级特效!😀
前端·javascript·vibecoding
CHB13 小时前
uni-app x 蒸汽模式 性能测试基准报告 Benchmark
uni-app·harmonyos
兆子龙15 小时前
ahooks useRequest 深度解析:一个 Hook 搞定所有请求
java·javascript
兆子龙15 小时前
React Suspense 从入门到实战:让异步加载更优雅
java·javascript
KKKK16 小时前
SSE(Server-Sent Events)流式传输原理和XStream实践
前端·javascript
子兮曰16 小时前
Humanizer-zh 实战:把 AI 初稿改成“能发布”的技术文章
前端·javascript·后端
Din17 小时前
主动取消的防抖
前端·javascript·typescript