| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- const e = `<template>
- <a
- class="s-tab-item"
- :class="{ active: isActive }"
- :data-value="value"
- role="tab"
- :aria-selected="isActive"
- :tabindex="isActive ? 0 : -1"
- @click="handClick"
- @keydown.left.prevent="ctx && ctx.prev()"
- @keydown.right.prevent="ctx && ctx.next()"
- >
- <slot>{{ label }}</slot>
- </a>
- </template>
- <script setup>
- import { computed, inject } from 'vue'
- defineOptions({ name: 'STabItem' })
- const props = defineProps({
- // 该标签对应的值,与 s-tab 的 activeKey 比对
- value: {
- type: [String, Number],
- required: true
- },
- // 纯文本标签;需要富内容时用默认插槽
- label: {
- type: String,
- default: ''
- }
- })
- // 由父级 s-tab 提供:activeValue 是 ref(读 .value 才响应式),select/prev/next 是方法
- const ctx = inject('sTabContext', null)
- const isActive = computed(() => (ctx ? ctx.activeValue.value === props.value : false))
- function handClick() {
- if (ctx) ctx.select(props.value)
- }
- <\/script>
- `;
- export {
- e as default
- };
|