This commit is contained in:
Zy
2026-06-09 10:10:43 +08:00
parent 93504e2a06
commit 0572000821
9 changed files with 55 additions and 18 deletions

View File

@@ -24,7 +24,7 @@
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { ref, computed, watch } from 'vue'
// 标签项类型
interface TabItem {
@@ -68,9 +68,23 @@ const tabs = computed<TabItem[]>(() => {
})
// ======================
// 当前激活值(响应式)
// 当前激活值(响应式 + 可同步父组件更新)
// ======================
const currentActiveValue = ref<string | number>(props.activeValue ?? tabs.value[0]?.value ?? '')
const currentActiveValue = ref<string | number>('')
// 初始化 + 父组件传值变化时自动同步(核心修复)
watch(
() => props.activeValue,
newVal => {
if (newVal !== null && newVal !== undefined) {
currentActiveValue.value = newVal
} else {
// 没有传默认值 → 选中第一个
currentActiveValue.value = tabs.value[0]?.value
}
},
{ immediate: true } // 一进页面就执行
)
// 事件
const emit = defineEmits<{