VUE----v-for基本用法

父元素:v-for="(  item ,  index  ) in list "  :key="index"

子元素:{{  item  }}             {{item.text}}

list代表被循环的数组

item表示数组内的子元素,数组里有多少个一级子元素,就有多少个遍历子元素

index代表下标,一般点击事件可以携带的参数

:key绑定唯一标识

子元素用{{ }} 绑定获取

 优点:只用增减数组,就能控制显示多少子元素,减少HTML代码,不再写死数据,方便以后对接口。

示例:

 

HTML:

<template>
	<view>
		<view class="wai">
			<view class="box" v-for="(item,index) in list" :key="index">
				<text>{{item.text}}</text>
			</view>
		</view>
	</view>
</template>

JS:

<script>
	export default {
		data() {
			return {
				list:[
					{text:'第1个'},
					{text:'第2个'},
					{text:'第3个'},
					{text:'第4个'},
					{text:'第5个'},
					{text:'第6个'},
					{text:'第7个'},
					{text:'第8个'}
				]
			}
		},
		   methods: {
			   
		     }
	}
</script>

CSS:

<style scoped>
	.wai{
		width: 100%;
		height: 412rpx;
		background-color: #55ffff;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}
	.box{
		width: 24%;
		height: 200rpx;
		background-color: #F0AD4E;
		margin-bottom: 6rpx;
		font-size: 40rpx;
	}
</style>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值