element Tabs标签二次封装

直接上代码

<template>
  <div class="tab-container">
    <el-tabs v-model="activeName" style="margin-top:15px;" :type="tabType" @tab-click="handleClick">
      <el-tab-pane v-for="item in tabMapOptions" :key="item.key" :label="item.label" :name="item.key">
        <keep-alive>
            <template v-if="key=='goods'">
                <all-goods v-if="item.key=='goods'"  @create="showCreatedTimes" />
            </template>
        </keep-alive>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
//这是tabPane要显示的组件
import AllGoods from '@/views/goodsManage/allGoods'
export default {
  name: 'Tab',
  props:{
    tabMapOptions:{
        type:Array,
        default:()=>{
            return []
        }
    },
    tabType:{
        type:String,
        default:'border-card'
    },
    type:{
        type:String,
        default:''
    },
    active:{
        type:String,
        default:''
    },

  },
  components: { AllGoods },
  data() {
    return {
      activeName: this.active,
      createdTimes: 0
    }
  },
  watch: {
    active(val) {
      this.$router.push(`${this.$route.path}?tab=${val}`)
    }
  },
  created() {
    // init the default selected tab
    const tab = this.$route.query.tab
    if (tab) {
      this.activeName = tab
    }
  },
  methods: {
    handleClick(tab, event){
        console.log("点击了Tabs:",tab, event);
    },
    showCreatedTimes() {
      this.createdTimes = this.createdTimes + 1
    }
  }
}
</script>

<style scoped>
  .tab-container {
    margin: 30px;
  }
</style>

组件的调用


// 产品管理-产品列表
<template>
    <div class="goods-list">
        <tabs 
            :tabMapOptions='tabMapOptions' 
            :active='activeName' 
            type='goods'
            tabType='border-card' 
        >
        </tabs>
      
    </div>
</template>
<script>
import Tabs from '@/components/Tabs/tabs'
export default {
    components:{
        Tabs,
    },
    data() {
        return {
            tabMapOptions: [
                { label: '全部', key: 'ALL' },
                { label: '待开发', key: 'Info' },
                { label: '上架', key: 'Role' },
                { label: '已上架', key: 'Putaway' },
                { label: '已停售', key: 'Halt' },
                { label: '已淘汰', key: 'weedOut' },
            ],
            
             activeName: 'ALL',

        };
    },
    methods: {
        //点击tabs标签出发的方法
        handleClick(tabs){
            console.log('tabs标签:',tabs);
        }
      
    }
  };
</script>

<style lang="scss" scoped>
.goods-list {
    padding:5px 15px 15px 15px;
}
</style>

成果展示
在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值