From 0eb0563fc1e60b71d0cc9776f83e51b02600d445 Mon Sep 17 00:00:00 2001 From: oat_dev Date: Tue, 23 Apr 2024 17:20:29 +0700 Subject: [PATCH] refactor: tab --- src/components/TabComponent.vue | 49 +++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/components/TabComponent.vue b/src/components/TabComponent.vue index b422fc17..74d08f74 100644 --- a/src/components/TabComponent.vue +++ b/src/components/TabComponent.vue @@ -5,18 +5,26 @@ import AppBox from './app/AppBox.vue'; const tab = ref(''); -const index = ref(0); const tabList = ref<{ name: string; label: string }[]>([]); function test() { - index.value++; tabList.value.push({ - name: `สาขาที่ ${index.value}`, - label: `สาขาที่ ${index.value}`, + name: `สาขาที่ ${tabList.value.length + 1}`, + label: `สาขาที่ ${tabList.value.length + 1}`, }); tab.value = tabList.value[tabList.value.length - 1].name; } + +async function close(index: number) { + if (tabList.value.length > 1) { + tabList.value.splice(index, 1); + } + // tab.value = await tabList.value[tabList.value.length - 1].name; + setTimeout(() => { + tab.value = `สาขาที่ ${tabList.value.length.toString()}`; + }, 10); +} - +