当前位置: 首页 > article >正文

uniapp vue3 梯形选项卡组件

实现的效果图:

切换选项卡显示不同的内容,把这个选项卡做成了一个组件,需要的自取。

// 组件名为 trapezoidalTab
<template>  
 <view class="pd24">
	 <view class="nav">
	   <!-- 左侧 -->
	   <view class="item" :class="{ active: activeIndex === 0 }" @click="changeTab(0)"> 
	 		<view :class=" activeIndex === 0 ? 'activeTxt black' : 'itemTxt' ">
	 			{{leftLabel}}
	 		</view>
	   </view>
	 	<!-- 右侧 -->
	 	<view class="item" :class="{ active: activeIndex === 1 }"  @click="changeTab(1)"> 
	 		<view :class="activeIndex == 1 ? 'activeTxt black' : 'itemTxt' ">
	 			{{rightLabel}}
	 		</view>
	 	</view>
	 </view> 
	 
	 <view class="content">
		 <view v-if='activeIndex === 0'>
			 <slot name="left"></slot>
		 </view>
		 <view v-if='activeIndex === 1'>
			  <slot name="right"></slot>
		 </view>
	 </view>
 </view> 
</template>  
  
<script setup> 
	import {
		ref,
		defineProps,
		defineEmits,
	} from 'vue'
	
	const props = defineProps({
		leftLabel: {
		  type: String,
		  default: '到店取'
		},
		rightLabel: {
		  type: String,
		  default: '直达送'
		},
		activeIndex: {
		  type: Number,
		  default: 0
		},
	})
	const emit = defineEmits(['changeTab'])
	const changeTab=(val)=> {
		emit('changeTab',val) 
	}  
</script>  
  
<style lang="scss" scoped>
	.nav{
		display: flex;
		align-items: flex-end;
	}
	.nav .item{
		flex: 1;
		height: 80rpx;
		background: #E6E6E6;
		border-radius: 10rpx 10rpx 0 0;
		position: relative;
		list-style: none;
	}
	.nav .item.active{
		height: 96rpx;
		background: #FFF;
	}
	.nav .item:first-child:before,  
	.nav .item:last-child:before {  
	    content: '';  
	    display: none;  
	    width: 20rpx;  
	    height: 100%;  
	    background: #FFF;  
	    position: absolute;  
	    top: 0;  
	    z-index: 10;  
	}  
	  
	.nav .item:first-child:before {  
	    right: -10rpx;  
	    border-radius: 0 10rpx 0 0;  
	    transform: skew(10deg);  
	}  
	  
	.nav .item:last-child:before {  
	    left: -10rpx;  
	    border-radius: 10rpx 0 0 0;  
	    transform: skew(-10deg);  
	}  
	  
	.nav .item.active:first-child:before,  
	.nav .item.active:last-child:before {  
	    display: block;  
	}
	.itemTxt{
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
		font-weight: 500;
		font-size: 28rpx;
		color: rgba(0,0,0,0.4);
	}
	.activeTxt{
		text-align: center;
		height: 96rpx;
		line-height: 96rpx;
		font-weight: bold;
		font-size: 32rpx;
	}
	
	.content{
		width: 100%;
		background: #fff;
	}
</style>

使用组件:

<trapezoidal-tab @changeTab="changeTab" :activeIndex='activeIndex'>
	<template v-slot:left>
		<view>左边部分内容</view>
	</template>
			
	<template v-slot:right>
		<view>右边部分内容</view>
	</template>
</trapezoidal-tab>

const activeIndex = ref(0) //tab选项卡 0:到店取 1:直达送
// 切换tab选项卡
const changeTab =(val)=>{
	activeIndex.value = val
}


http://www.kler.cn/news/312411.html

相关文章:

  • springboot调用python脚本实现ocr图片文字识别功能
  • Maven踩坑——父模块生命周期的操作会被子模块继承
  • 零信任安全架构--持续验证
  • Android 12系统源码_窗口管理(八)WindowConfiguration的作用
  • 基于SpringBoot+Vue+MySQL的养老院管理系统
  • SSMP+ajax实现广告系统的分页效果
  • 有关JS下隐藏的敏感信息
  • 【C++篇】~类和对象(中)
  • 【C++】STL----stack和queue常见用法
  • 请求响应-05.请求-日期参数JSON参数
  • Vue2时间轴组件(TimeLine/分页、自动顺序播放、暂停、换肤功能、时间选择,鼠标快速滑动)
  • HarmonyOS 应用获取公钥和 MD5 指纹签名信息
  • MySQL——数据库的高级操作(二)用户管理(4)修改用户密码
  • 第6天:趋势轮动策略开发(年化18.8%,大小盘轮动加择时)
  • 基于STM32设计的水渠闸门远程控制系统(华为云IOT)(226)
  • 14_Python面向对象
  • 【LeetCode】每日一题 2024_9_17 公交路线(BFS)
  • Effective Java 学习笔记45-48 Stream
  • VS code 查看 ${workspaceFolder} 目录指代路径
  • 设计模式-行为型模式-解释器模式
  • Python 解析 Charles JSON Session File (.chlsj)
  • 攻防世界--->gametime
  • 数据结构-2.7.单链表的查找与长度计算
  • linux-系统管理与监控-磁盘管理
  • mysql学习教程,从入门到精通,SQL DISTINCT 子句 (16)
  • DeDeCMS靶场漏洞复现
  • 前端vue-父传子
  • 2024年亲测好用的四大在线翻译工具大盘点!
  • keras和tensorflow可用的一组版本
  • 【百日算法计划】:每日一题,见证成长(013)