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>
		
相关推荐
雾岛听蓝37 分钟前
Qt操作指南:窗口组成与菜单栏
开发语言·经验分享·笔记·qt
zopple1 小时前
Laravel vs ThinkPHP:PHP框架终极对决
开发语言·php·laravel
松☆1 小时前
C++ 算法竞赛题解:P13569 [CCPC 2024 重庆站] osu!mania —— 浮点数精度陷阱与 `eps` 的深度解析
开发语言·c++·算法
耿雨飞1 小时前
Python 后端开发技术博客专栏 | 第 06 篇 描述符与属性管理 -- 理解 Python 属性访问的底层机制
开发语言·python
耿雨飞1 小时前
Python 后端开发技术博客专栏 | 第 08 篇 上下文管理器与类型系统 -- 资源管理与代码健壮性
开发语言·python
kyriewen111 小时前
项目做了一半想重写?这套前端架构让你少走3年弯路
前端·javascript·chrome·架构·ecmascript·html5
2601_949194262 小时前
Python爬虫完整代码拿走不谢
开发语言·爬虫·python
c***89202 小时前
python爬虫——爬取全年天气数据并做可视化分析
开发语言·爬虫·python
aq55356002 小时前
C语言、C++和C#:三大编程语言核心差异详解
java·开发语言·jvm
并不喜欢吃鱼2 小时前
从零开始C++----七.继承及相关模型和底层(上篇)
开发语言·c++