vue tabs组件样式效果

vue yekong 79℃

vue tabs组件样式效果

组件代码

<template>
	<div class="tabs">
		<div class="tab cur" :class="{active:active==index}" @click="getactive(index)" v-for="(item,index) in list"
			:key="index"><span>{{ item }}</span>
		</div>
	</div>
</template>
<script>
	export default {
		name: "tabs",
		components: {},
		props: {
			list: {
				type: Array,
				default () {
					return [];
				}
			}
		},
		data() {
			return {
				active: 0
			}
		},
		watch: {},
		mounted() {},
		methods: {
			getactive(e) {
				this.active = e
				this.$emit('getactive', e)
			},
		}
	}
</script>
<style scoped lang="scss">
	.tabs {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: nowrap;
		flex-direction: row;
		padding-left: 30rpx;
		padding-right: 30rpx;
		height: 120rpx;
		margin: auto;

		.tab {
			font-size: 24rpx;
			font-family: MicrosoftYaHei;
			font-weight: 400;
			color: #000000;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-wrap: nowrap;
			flex-direction: column;
			min-width: 88rpx;
			height: 60rpx;
			background: #F5F6FC;
			border-radius: 8rpx;
			margin-right: 16rpx;

			span {
				font-size: 28rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #151852;
				padding: 0 24rpx;
			}

		}

		.tab.active {
			background: rgba(64, 135, 255, 1);

			span {
				color: #FFFFFF;
			}
		}
	}
</style>

使用组件

<tab @getactive='getactive' :list='listtab'></tab>
import tab from '@/components/tab/tab.vue'
components: {
			tab
		},

data

current: 0,
listtab: ['日', '月'],

js

getactive(item) {
				this.current = item
			},
喜欢 (0)