<template>
  <div class="tab">
<!--    tab 表格 ,传入tabHeader,通过tabHeader的key来渲染对应的slot插槽-->
    <div class="tab-headers">
      <div
          v-for="(item,i) in headers"
          :key="item.key"
          @click="nowKey=item.key"
          :class="`header-menu ${item.key===nowKey?'now':''} `">
        {{item.text}}
      </div>
    </div>
    <div class="tab-view" >
      <slot :name="nowKey" ></slot>
    </div>

  </div>
</template>

<script>
export default {
  name: "qTab",
  props:{
    headers: {
      default(){
        return []
      }
    }
  },
  data(){
    return {
      nowKey: this.headers.length?this.headers[0].key:''
    }
  }
}
</script>

<style scoped>
.tab{
  width: 100%;
  height: auto;
}
.tab-headers{
  width: 100%;
  height: 45px;
  display: flex;
}
.tab-headers .header-menu{
  padding: 5px 15px;
  border-radius: 3px;
  margin: 5px;
  cursor: pointer;
  box-shadow: 0 0 5px gainsboro;
  /*font-size: 1.2rem;*/


}
.tab-headers .header-menu.now{
  background-color: #50b8c9;
  color: white;
}
.tab-headers .header-menu:hover{
  background-color: skyblue;
  color: white;
}
.tab-view{
  width: 100%;
  height: auto;
  border-top: 1px solid gainsboro;
}
</style>
