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>
		
相关推荐
Appoint_x4 小时前
设计稿自己会说话:我用 Claude 给 Figma 做了个 AI 上下文插件
前端·javascript
豹哥学前端4 小时前
浏览器console里的双中括号 `[[ ]]`
前端·javascript·ecmascript 6
迷渡4 小时前
聊一聊 Bun 用 Rust 重写这件事
开发语言·后端·rust
西洼工作室4 小时前
个人开发者接入阿里云号码认证服务AliCloud-NirvanaPns实现一键登录
python·阿里云·uni-app·全栈·认证授权
古怪今人4 小时前
Gradle构建工具 Groovy/Kotlin DSL的现代化自动化构建工具
开发语言·kotlin·自动化
赏金术士4 小时前
Kotlin 协程与挂起函数(Coroutines & suspend)入门到实战
android·开发语言·kotlin
y = xⁿ4 小时前
Java并发八股学习日记
java·开发语言·学习
你很易烊千玺4 小时前
JS 数组所有变态遍历・完整案例 + 场景 + 对比
javascript·数组
xifangge20255 小时前
【深度排障】从 OS 底层寻址剖析 javac 不是内部或外部命令 核心报错:变量空间隔离与自动化部署终极范式
java·开发语言·jdk·自动化
肖恩想要年薪百万5 小时前
JSP中常用JSTL标签
java·开发语言·状态模式