【无标题】vue+uni 背景色随机或者按照数组来展示

这里是引用
引用了http://t.csdnimg.cn/oK8W1这位作者的颜色

下面是效果
颜色块的展示

<view class="content">
	<view class="content_box" :style="{'background':item.color}" v-for="(item, index) in courseList"
		:key="index" @click="goRecords(item)">
		<view class="content_title">
			{{item.name}}
		</view>
	</view>
</view>
getList() {
	this.courseList = []
	for (var i = 0; i < 10; i++) {
		this.courseList.push({
			name: '这是演示模板',
			img: '',
			color: ''
		})
	}
	var color = ['#ECAD9E', '#F4606C', '#19CAAD', '#8CC7B5', '#A0EEE1',
		'#BEE7E9', '#BEEDC7', '#D6D5B7', '#D1BA74', '#E6CEAC'
	]
	this.courseList.map((item, index) => {
		let colorIndex = Math.floor(index / (this.courseList.length / color.length))
		// let colorIndex = Math.floor(Math.random()*10)
		item.color = color[colorIndex]
	})
	console.log(this.courseList)
},

<style lang="scss" scoped>

	.content {
		display: flex;
		padding: 20px;
		flex-wrap: wrap;
		box-sizing: border-box;
		justify-content: space-between;
		flex-direction: row;

		.content_box {
			box-sizing: border-box;
			width: 48%;
			height: 150px;
			padding: 0 5%;
			margin: 2% 0;
			border-radius: 5px;
			border: 1px solid #eeee;
			display: block;
			position: relative;

			.content_title {
				position: absolute;
				bottom: 0px;
				color: white;
				background: rgba(0, 0, 0, 0.2);
				width: 100%;
				left: 0;
				padding: 5px;
				border-bottom-left-radius: 5px;
				border-bottom-right-radius: 5px;
				box-sizing: border-box;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				line-clamp: 2;
				-webkit-box-orient: vertical;
				font-size: 13px;
			}

		}

	}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值