|
| 1 | +<template> |
| 2 | + <DataTable |
| 3 | + :headers="headers" |
| 4 | + :items="items" |
| 5 | + @expand-row="loadIntroduction" |
| 6 | + > |
| 7 | + <template #expand="item"> |
| 8 | + <div |
| 9 | + v-if="item.introduction" |
| 10 | + style="padding: 15px" |
| 11 | + > |
| 12 | + {{ item.introduction }} |
| 13 | + </div> |
| 14 | + </template> |
| 15 | + </DataTable> |
| 16 | +</template> |
| 17 | + |
| 18 | +<script lang="ts" setup> |
| 19 | +import { |
| 20 | + computed, ref, reactive, toRefs, |
| 21 | +} from 'vue'; |
| 22 | +import type { |
| 23 | + Header, Item, FilterOption, ClickRowArgument, HeaderItemClassNameFunction, BodyItemClassNameFunction, BodyRowClassNameFunction, |
| 24 | +} from '../types/main'; |
| 25 | +import DataTable from '../components/DataTable.vue'; |
| 26 | +
|
| 27 | +import { mockClientNestedItems, mockClientItems, mockDuplicateClientNestedItems } from '../mock'; |
| 28 | +const headers: Header[] = [ |
| 29 | + { text: 'PLAYER', value: 'player' }, |
| 30 | + { text: 'TEAM', value: 'team', sortable: true }, |
| 31 | +]; |
| 32 | +
|
| 33 | +const items = ref<Item[]>([ |
| 34 | + { player: 'Stephen Curry', team: 'GSW' }, |
| 35 | + { player: 'Lebron James', team: 'LAL' }, |
| 36 | + { player: 'Kevin Durant', team: 'BKN' }, |
| 37 | + { player: 'Giannis Antetokounmpo', team: 'MIL' }, |
| 38 | +]); |
| 39 | +
|
| 40 | +const mockItemIntroduction = async (name: string): Promise<string> => { |
| 41 | + await new Promise((s) => setTimeout(s, 2000)); |
| 42 | + const introduction: Record<string, string> = { |
| 43 | + 'Stephen Curry': 'Wardell Stephen Curry II is an American professional basketball player for the Golden State Warriors of the National Basketball Association (NBA).', |
| 44 | + 'Lebron James': 'LeBron Raymone James Sr is an American professional basketball player for the Los Angeles Lakers of the National Basketball Association (NBA).', |
| 45 | + 'Kevin Durant': 'Kevin Wayne Durant also known by his initials KD, is an American professional basketball player for the Brooklyn Nets of the National Basketball Association (NBA).', |
| 46 | + 'Giannis Antetokounmpo': 'Giannis Sina Ugo Antetokounmpo (né Adetokunbo; December 6, 1994) is a Greek-Nigerian professional basketball player for the Milwaukee Bucks of the National Basketball Association (NBA).', |
| 47 | + }; |
| 48 | + return introduction[name]; |
| 49 | +}; |
| 50 | +
|
| 51 | +const loadIntroduction = async (index: number): Promise<void> => { |
| 52 | + const expandedItem = items.value[index]; |
| 53 | + if (!expandedItem.introduction) { |
| 54 | + expandedItem.expandLoading = true; |
| 55 | + expandedItem.introduction = await mockItemIntroduction(expandedItem.player); |
| 56 | + expandedItem.expandLoading = false; |
| 57 | + } |
| 58 | +}; |
| 59 | +</script> |
0 commit comments