-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83c42cd
commit bab9e9d
Showing
4 changed files
with
165 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script setup> | ||
const items = [{ | ||
label: 'Tab1', | ||
content: 'This is the content shown for Tab1' | ||
}, { | ||
label: 'Tab2', | ||
content: 'And, this is the content for Tab2' | ||
}, { | ||
label: 'Tab3', | ||
content: 'Finally, this is the content for Tab3' | ||
}] | ||
function onChange (index) { | ||
const item = items[index] | ||
alert(`${item.label} was clicked!`) | ||
} | ||
</script> | ||
|
||
<template> | ||
<UTabs :items="items" @change="onChange" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<script setup> | ||
const items = [{ | ||
label: 'Tab1', | ||
content: 'This is the content shown for Tab1' | ||
}, { | ||
label: 'Tab2', | ||
content: 'And, this is the content for Tab2' | ||
}, { | ||
label: 'Tab3', | ||
content: 'Finally, this is the content for Tab3' | ||
}] | ||
const route = useRoute() | ||
const router = useRouter() | ||
const selected = computed({ | ||
get () { | ||
const index = items.findIndex((item) => item.label === route.query.tab) | ||
if (index === -1) { | ||
return 0 | ||
} | ||
return index | ||
}, | ||
set (value) { | ||
// Hash is specified here to prevent the page from scrolling to the top | ||
router.replace({ query: { tab: items[value].label }, hash: '#control-the-selected-index' }) | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<UTabs v-model="selected" :items="items" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters