自定義Tabs標籤頁組件(vue)

不知道有沒有和我一樣項目中用的到Ant Design of Vue的Tabs組件在測試環境上打包時是無效的,於是手寫個組件

我會寫在src的componets下

我所用到的傳值都是用類型1或2來判斷或者中英文

父組件

<template>
  <div>
    <!-- 操作tab區域 -->
    <div class="tab-box">
      <div
        class="tab-item"
        v-for="(item, index) in tabName"
        :key="index"
        :class="{tabActive:tabCode == index}"
        @click="getTab(index)"
      >{{item}}</div>
    </div>
  </div>
</template>

<script>
export default {
  props: ['tabName', 'type'],
  data() {
    return {
      tabCode: 0,
      //   tabName: ['tab1', 'tab2'],
      send: 1
    }
  },
  mounted() {},
  methods: {
    getTab(index) {
      this.tabCode = index
      if (index == 0) {
        // this.type = 1
        if (typeof this.type == 'string') {
          this.send = 'CN'
        } else {
          this.send = 1
        }
        this.$emit('typeFn', this.send)
      } else {
        if (typeof this.type == 'string') {
          this.send = 'EN'
        } else {
          this.send = 2
        }
        this.$emit('typeFn', this.send)
      }
      // console.log('this.type: ', this.send)
      //   this.$emit('typeFn', this.type)
    }
  }
}
</script>

<style lang="scss" scoped>
.tab-box {
  display: flex;
  margin-bottom: 18px;
  .tab-item {
    width: 100px;
    height: 35px;
    text-align: center;
    line-height: 35px;
    cursor: pointer;
    border: 1px solid #1890ff;
  }
  .tabActive {
    background-color: #1890ff;
    color: #fff;
  }
}
</style>

子組件

<template>
 <TabBar :tabName="tabName" :type="subject" @typeFn="typeFn" />
</template>

<script>
import TabBar from '@/components/TabBar'
export default {
  components: { TabBar },
   data() {
   subject: 'CN' //定義你需要的
   }
}
 methods: {
 typeFn(value) {
      this.subject = value; //寫你的邏輯
    }
 }
 
</script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章