vue中不同的状态对应不同的样式

vue中不同的状态对应不同的样式

在具体的开发中,不同的状态应该对应不同的样式。
这里我给大家举个列子,
周末的时候,状态处于放假中
当处于周一时,状态处于上课中
这时候可以利用vue的计算属性来写:

computed: {
		stateConputed(val) {
			return function(val) {
				let returnData = this.stateList.filter(item => {
					return item.state === val;
				});
				return returnData[0];
			};
		}
	}

具体代码和效果,如下所示:

<template>
	<view class="content">
		<view class="list" v-for="(item, index) in list" :key="index" @click="handleClickDetail">
			<view class="list-top">
				<view class="list-top-left">
					<text>{{ item.time }}</text>
				</view>
				<view class="list-top-right" :style="{ 'background-color': stateConputed(item.state).color }">
					<text>{{ stateConputed(item.state).name }}</text>
				</view>
			</view>
			<view class="list-bottom">
				<view class="list-bottom-item">
					<text class="name">姓名</text>
					<text class="name-list">{{ item.people }}</text>
				</view>
				<view class="list-bottom-item">
					<text class="name">内容</text>
					<text class="name-list">{{ item.text }}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			stateList: [
				{
					state: 1,
					name: '放假中',
					color: '#1CC8EE'
				},
				{
					state: 2,
					name: '上课中',
					color: '#00BA88'
				}
			],
			list: [
				{ time: '周末', state: 1, people: '派大星', text: '我要去游乐园' },
				{ time: '周一', state: 2, people: '海绵宝宝', text: '数学、英语、语文' }
			]
		};
	},
	computed: {
		stateConputed(val) {
			return function(val) {
				let returnData = this.stateList.filter(item => {
					return item.state === val;
				});
				return returnData[0];
			};
		}
	}
};
</script>

<style lang="scss" scoped>
.content {
	padding: 32rpx 24rpx;
	box-sizing: border-box;
	background: #f7f7fc;
	.list {
		width: 100%;
		opacity: 1;
		background: #ffffff;
		border-radius: 30rpx;
		margin-bottom: 20rpx;
		padding: 50rpx 56rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.list-top {
			display: flex;
			justify-content: space-between;
			.list-top-left {
				display: flex;
				align-items: center;
				text {
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Medium;
					font-weight: bold;
					color: #e4b3fc;
					margin-left: 17rpx;
				}
			}
			.list-top-right {
				width: 130rpx;
				height: 48rpx;
				opacity: 1;
				border-radius: 6rpx;
				text-align: center;
				line-height: 48rpx;
				text {
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					color: #ffffff;
				}
			}
		}
		.list-bottom {
			display: flex;
			flex-direction: column;
			.list-bottom-item {
				margin-top: 20rpx;
				display: flex;
				justify-content: flex-start;
				align-items: flex-start;
				.name {
					width: 64rpx;
					height: 44rpx;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					color: #888888;
					margin-right: 32rpx;
				}
				.name-list {
					width: 80%;
					// height: 88rpx;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					color: #333333;
				}
			}
		}
	}
}
</style>

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值