vue 最简单的tab选项卡

选项卡

概述

本tab选项卡demo只实现基本的tab选项卡切换,具体样式请依据项目进行修改优化

效果图

在这里插入图片描述

代码demo

<!-- 产品详情 :产品介绍、产品规格、产品售后 -->
<template>
  <div class="intro">
      <ul class="tabs">
        <li class="tab" v-for="(item,index) in tabs" :key="index" :class="{current:index==current}" @click="current=index">{{item.title}}</li>
      </ul>
      <div class="con">
        <div class="con_box" v-if="current==0">
          产品简介
        </div>
        <div class="con_box" v-if="current==1">
          产品规格
        </div>
        <div class="con_box" v-if="current==2">
          产品售后
        </div>
      </div>
  </div>
</template>
<script>
export default {
  data(){
    return{
      current:0,
      tabs:[
        {
          title:'产品简介'
        },
        {
          title:'产品规格'
        },
        {
          title:'产品售后'
        },
      ]
    }
  }
}
</script>
<style lang="scss" scoped>
.intro{}
  .tabs{
    display: flex;
    .tab{
      color: #283242;
      cursor: pointer;
      padding:4px 10px;
      &.current{
        color:#1870FF ;
      }
    }
  }
</style>

使用id的选项卡

template

<ul class="tabs">
  <li class="tab" v-for="(item, index) in tabs" :key="index" :class="{ current: item.tid == currentTid }" @click="currentTid = item.tid">{{ item.title }}</li>
</ul>
<div class="con">
  <div class="con_box" v-if="currentTid == 't0'">产品简介</div>
  <div class="con_box" v-if="currentTid == 't1'">产品规格</div>
  <div class="con_box" v-if="currentTid == 't2'">产品售后</div>
</div>

data

currentTid: 't0',
tabs: [
  {
    title: "产品简介",
    tid:'t0'
  },
  {
    title: "产品规格",
    tid:'t1'
  },
  {
    title: "产品售后",
    tid:'t2'
  },
],

style

.tabs {
	display: flex;
	.tab {
	  color: #283242;
	  cursor: pointer;
	  padding: 4px 10px;
	  &.current {
	    color: #1870ff;
	  }
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值