Skip to content

Commit

Permalink
修改 tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
InfernalAzazel committed Nov 26, 2024
1 parent f357e60 commit f3fc4cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 0 additions & 2 deletions docs/cn/other/components/DemoProTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const tabs = ref<ProTabData[]>([
{ title: '我的账户', path: '/account' },
{ title: '设置', path: '/settings' }
])
// 下拉菜单选项
// 定义下拉菜单选项
const dropdownOptions = [
{
label: '刷新',
Expand Down
13 changes: 13 additions & 0 deletions packages/k-naiveui-pro/src/components/ProTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ export interface ProTabsProps {
}
defineOptions({name: 'ProTabs', inheritAttrs: false});
defineExpose({
setSelected
});
const props = withDefaults(defineProps<ProTabsProps>(), {
borderStyle: 'all', // 默认值为完整边框
});
const modelValue = defineModel<ProTabData[]>({default: []});
const emit = defineEmits<{
(e: 'select', path: string): void; // 选项卡切换事件
}>();
Expand Down Expand Up @@ -52,6 +56,15 @@ function handleSelect(index: number) {
selected.value = index; // 更新当前选中的索引
emit('select', modelValue.value[index].path || ''); // 触发选中事件
}
// 设置选中的选项卡
function setSelected(index: number) {
if (index >= 0 && index < modelValue.value.length) {
selected.value = index; // 更新选中索引
emit('select', modelValue.value[index]?.path || ''); // 触发选中事件
}
}
</script>

<template>
Expand Down

0 comments on commit f3fc4cc

Please sign in to comment.