STabItem2.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const e = `<template>
  2. <a
  3. class="s-tab-item"
  4. :class="{ active: isActive }"
  5. :data-value="value"
  6. role="tab"
  7. :aria-selected="isActive"
  8. :tabindex="isActive ? 0 : -1"
  9. @click="handClick"
  10. @keydown.left.prevent="ctx && ctx.prev()"
  11. @keydown.right.prevent="ctx && ctx.next()"
  12. >
  13. <slot>{{ label }}</slot>
  14. </a>
  15. </template>
  16. <script setup>
  17. import { computed, inject } from 'vue'
  18. defineOptions({ name: 'STabItem' })
  19. const props = defineProps({
  20. // 该标签对应的值,与 s-tab 的 activeKey 比对
  21. value: {
  22. type: [String, Number],
  23. required: true
  24. },
  25. // 纯文本标签;需要富内容时用默认插槽
  26. label: {
  27. type: String,
  28. default: ''
  29. }
  30. })
  31. // 由父级 s-tab 提供:activeValue 是 ref(读 .value 才响应式),select/prev/next 是方法
  32. const ctx = inject('sTabContext', null)
  33. const isActive = computed(() => (ctx ? ctx.activeValue.value === props.value : false))
  34. function handClick() {
  35. if (ctx) ctx.select(props.value)
  36. }
  37. <\/script>
  38. `;
  39. export {
  40. e as default
  41. };