6/9
This commit is contained in:
@@ -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<{
|
||||
|
||||
Reference in New Issue
Block a user