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

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.lryc.cn/news/442495.html

相关文章:

  • 如何在微信小程序中实现WebSocket连接
  • 二级等保测评中安全物理环境的重要性及高危项分析
  • C++11——lambda
  • Dubbo3序列化安全问题
  • 秒懂Linux之共享内存
  • 【计算机网络】网络层协议解析
  • sqlist void reverse(SqList A)
  • 聊聊Thread Local Storage
  • WEB攻防-JS项目Node.js框架安全识别审计验证绕过
  • STM32——SPI
  • 【云安全】云上资产发现与信息收集
  • flask搭建微服务器并训练CNN水果识别模型应用于网页
  • 数据篇| 关于Selenium反爬杂谈
  • MySQL高阶1890-2020年最后一次登录
  • update-alternatives官方手册
  • cesium.js 入门到精通(5-2)
  • LINUX的PHY抽象层——PAL
  • 优先级队列(堆)
  • 帧率和丢帧分析理论
  • solidwork找不到曲面
  • mac安装JetBtains全家桶新版本时报错:Cannot start the IDE
  • MVCC机制解析:提升数据库并发性能的关键
  • 如何使用Postman搞定带有token认证的接口实战!
  • Linux Vim编辑器常用命令
  • 【Android】浅析MVC与MVP
  • spark 面试题
  • 青柠视频云——如何开启HTTPS服务?
  • 2016年国赛高教杯数学建模A题系泊系统的设计解题全过程文档及程序
  • vue-使用refs取值,打印出来是个数组??
  • 微服务_入门1