qTab.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <div class="tab">
  3. <!-- tab 表格 ,传入tabHeader,通过tabHeader的key来渲染对应的slot插槽-->
  4. <div class="tab-headers">
  5. <div
  6. v-for="(item,i) in headers"
  7. :key="item.key"
  8. @click="nowKey=item.key"
  9. :class="`header-menu ${item.key===nowKey?'now':''} `">
  10. {{item.text}}
  11. </div>
  12. </div>
  13. <div class="tab-view" >
  14. <slot :name="nowKey" ></slot>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. name: "qTab",
  21. props:{
  22. headers: {
  23. default(){
  24. return []
  25. }
  26. }
  27. },
  28. data(){
  29. return {
  30. nowKey: this.headers.length?this.headers[0].key:''
  31. }
  32. }
  33. }
  34. </script>
  35. <style scoped>
  36. .tab{
  37. width: 100%;
  38. height: auto;
  39. }
  40. .tab-headers{
  41. width: 100%;
  42. height: 45px;
  43. display: flex;
  44. }
  45. .tab-headers .header-menu{
  46. padding: 5px 15px;
  47. border-radius: 3px;
  48. margin: 5px;
  49. cursor: pointer;
  50. box-shadow: 0 0 5px gainsboro;
  51. /*font-size: 1.2rem;*/
  52. }
  53. .tab-headers .header-menu.now{
  54. background-color: #50b8c9;
  55. color: white;
  56. }
  57. .tab-headers .header-menu:hover{
  58. background-color: skyblue;
  59. color: white;
  60. }
  61. .tab-view{
  62. width: 100%;
  63. height: auto;
  64. border-top: 1px solid gainsboro;
  65. }
  66. </style>