Vue-自定义手写tabs

郏志学
2023-12-01
<template>
  <div>
    <div class="container">
      <div class="main_tabs">
        <div class="main_tab" v-for="item in ruleCodes" :key="item.value" :label="item.value" @click="handleClick(item)" :class="number == item.value ?'blue':''">
          {{ item.label }}
        </div>
      </div>

      <div v-if="number === '1'">吃桃子</div>
      <div v-if="number === '2'">吃香蕉</div>
      <div v-if="number === '3'">吃西瓜</div>
    </div>
  </div>
</template>

<script>
export default {

  data () {
    return {
      model: [{
        ruleCode: ''
      }],
      ruleCodes: [
        { label: '今天', value: '1' },
        { label: '明天', value: '2' },
        { label: '后天', value: '3' }
      ],
      number: ''
    }
  },

  created () {
  },

  methods: {
    // tab点击事件
    handleClick (item) {
      this.number = item.value
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  width: 450px !important;
  height: 580px;
  background-color: #fff;
  .main_tabs {
    display: flex;
    flex: 0 0 33.3333%;
    .main_tab {
      width: 100%;
      height: 30px;
      border: 1px solid #4797c7;
      text-align: center;
      line-height: 30px;
    }
  }
  .blue {
    background-color: #2e5c9f;
    color: #fff;
  }
}
</style>

 类似资料: