SlideShare a Scribd company logo
Babel Coder
VUE COMPONENTS
Babel Coder
COMPONENTS
<script setup lang="ts">
const { data: articles } = useFetch('/api/articles')
</script>
<template>
<h1>Article List</h1>
<table>
<thead>
<tr>
<td>ID</td>
<td>Title</td>
<td>Excerpt</td>
</tr>
</thead>
<tbody>
<tr v-for="article of articles" :key="article.id" @click="console.log(article.id)">
<td>{{ article.id }}</td>
<td>{{ article.title }}</td>
<td>{{ article.excerpt }}</td>
</tr>
</tbody>
</table>
</template>
Babel Coder
COMPONENTS
<script setup lang="ts">
const { data: articles } = useFetch('/api/articles')
</script>
<template>
<ArticleList :articles="articles" />
</template>
<script setup lang="ts">
interface Article {
id: number
title: string
excerpt: string
}
const { articles } = de
fi
neProps<{ articles: Article[] | null }>()
</script>
<template>
<h1>Article List</h1>
<table>
<thead>
<tr>
<td>ID</td>
<td>Title</td>
<td>Excerpt</td>
</tr>
</thead>
<tbody>
<tr v-for="article of articles" :key="article.id" @click="console.log(article.id)">
<td>{{ article.id }}</td>
<td>{{ article.title }}</td>
<td>{{ article.excerpt }}</td>
</tr>
</tbody>
</table>
</template> components/article/ArticleList.vue
Babel Coder
COMPONENTS
<script setup lang="ts">
import type { Column } from '~/components/ui/UiDataTable.vue'
import type { ArticleItem } from '~/server/api/articles.get'
const { data: articles } = useFetch('/api/articles')
const columns: Column<ArticleItem>[] = [
{ name: 'ID',
fi
eld: 'id' },
{ name: 'Title',
fi
eld: 'title' },
{ name: 'Excerpt',
fi
eld: 'excerpt' },
]
</script>
<template>
<UiDataTable title="Article List" :columns="columns" :rows="articles" />
</template>
Babel Coder
COMPONENTS
<script setup lang="ts" generic="T extends { id: number }">
export interface Column<Row> {
name: string
fi
eld: keyof Row
}
interface Props {
title: string
columns: Column<T>[]
rows: T[] | null
}
const { title, columns, rows } = de
fi
neProps<Props>()
</script>
<template>
<h1>{{ title }}</h1>
<table>
<thead>
<tr>
<td v-for="column of columns" :key="column.
fi
eld">
{{ column.name }}
</td>
</tr>
</thead>
<tbody>
<tr v-for="row of rows" :key="row.id" @click="console.log(row.id)">
<td v-for="column of columns" :key="column.
fi
eld">
{{ row[column.
fi
eld] }}
</td>
</tr>
</tbody>
</table>
</template>
components/ui/UiDataTable.vue
Babel Coder
DEFAULT VALUES
<script setup lang="ts">
import type { Column } from '~/components/ui/UiDataTable.vue'
import type { ArticleItem } from '~/server/api/articles.get'
const columns: Column<ArticleItem>[] = [
{ name: 'ID',
fi
eld: 'id' },
{ name: 'Title',
fi
eld: 'title' },
{ name: 'Excerpt',
fi
eld: 'excerpt' },
]
</script>
<template>
<UiDataTable :columns="columns" />
</template>
Babel Coder
DEFAULT VALUES
<script setup lang="ts" generic="T extends { id: number }">
export interface Column<Row> {
name: string
fi
eld: keyof Row
}
interface Props {
title?: string
columns: Column<T>[]
rows?: T[] | null
}
const { title, columns, rows } = withDefaults(de
fi
neProps<Props>(), {
title: 'Data Table',
rows: () => [],
})
</script>
<template>
<h1>{{ title }}</h1>
<div v-if="rows?.length === 0">
No data found
</div>
<table v-else>
<thead>
<tr>
<td v-for="column of columns" :key="column.
fi
eld">
{{ column.name }}
</td>
</tr>
</thead>
<tbody>
<tr v-for="row of rows" :key="row.id" @click="console.log(row.id)">
<td v-for="column of columns" :key="column.
fi
eld">
{{ row[column.
fi
eld] }}
</td>
</tr>
</tbody>
</table>
</template>
components/ui/UiDataTable.vue
Babel Coder
EMIT
<script setup lang="ts">
import type { Column } from '~/components/ui/UiDataTable.vue'
import type { ArticleItem } from '~/server/api/articles.get'
const { data: articles } = useFetch('/api/articles')
const columns: Column<ArticleItem>[] = [
{ name: 'ID',
fi
eld: 'id' },
{ name: 'Title',
fi
eld: 'title' },
{ name: 'Excerpt',
fi
eld: 'excerpt' },
]
</script>
<template>
<UiDataTable
title="Article List"
:columns="columns"
:rows="articles"
@change="console.log($event)"
/>
</template>
Babel Coder
EMIT
<script setup lang="ts" generic="T extends { id: number }">
export interface Column<Row> {
name: string
fi
eld: keyof Row
}
interface Props {
title?: string
columns: Column<T>[]
rows?: T[] | null
}
const { title, columns, rows } = withDefaults(de
fi
neProps<Props>(), {
title: 'Data Table',
rows: () => [],
})
const emit = de
fi
neEmits<{
(e: 'change', id: number): void
}>()
</script>
<template>
<h1>{{ title }}</h1>
<div v-if="rows?.length === 0">
No data found
</div>
<table v-else>
<thead>
<tr>
<td v-for="column of columns" :key="column.
fi
eld">
{{ column.name }}
</td>
</tr>
</thead>
<tbody>
<tr v-for="row of rows" :key="row.id" @click="emit('change', row.id)">
<td v-for="column of columns" :key="column.
fi
eld">
{{ row[column.
fi
eld] }}
</td>
</tr>
</tbody>
</table>
</template>
components/ui/UiDataTable.vue
Babel Coder
SLOT
<script setup lang="ts">
</script>
<template>
<header>Header</header>
<p>Content</p>
<footer>Footer</footer>
</template>
<script setup lang="ts">
</script>
<template>
<UiCard />
</template>
components/ui/UiCard.vue
Babel Coder
DEFAULT SLOT
<script setup lang="ts">
</script>
<template>
<header>Header</header>
<p><slot /></p>
<footer>Footer</footer>
</template>
<script setup lang="ts">
</script>
<template>
<UiCard>My Content</UiCard>
</template>
components/ui/UiCard.vue
Babel Coder
NAMED SLOT
<script setup lang="ts">
</script>
<template>
<header><slot name="header" /></header>
<p><slot /></p>
<footer><slot name="footer" /></footer>
</template>
<script setup lang="ts">
</script>
<template>
<UiCard>
<template #header>
My Header
</template>
<template #default>
My Content
</template>
<template #footer>
My Footer
</template>
</UiCard>
</template>
components/ui/UiCard.vue
My Content
Babel Coder
FALLBACK CONTENT
<script setup lang="ts">
</script>
<template>
<header>
<slot name="header">
Header
</slot>
</header>
<p><slot>Content</slot></p>
<footer>
<slot name="header">
Footer
</slot>
</footer>
</template>
<script setup lang="ts">
</script>
<template>
<UiCard>
<template #header>
My Header
</template>
My Content
<template #footer>
My Footer
</template>
</UiCard>
</template>
components/ui/UiCard.vue

More Related Content

PPTX
Lect# 1 html part ii
PPTX
RDBMS oracle function RDBMSRDBMSRDBMS.pptx
PPTX
8. Php MongoDB stergerea unui document
PPTX
9. Php MongoDB cautarea unui document
DOC
Ex[1].3 php db connectivity
PPTX
7. Php MongoDB editarea unui document
PPTX
Html 5-tables-forms-frames (1)
Lect# 1 html part ii
RDBMS oracle function RDBMSRDBMSRDBMS.pptx
8. Php MongoDB stergerea unui document
9. Php MongoDB cautarea unui document
Ex[1].3 php db connectivity
7. Php MongoDB editarea unui document
Html 5-tables-forms-frames (1)

Similar to vue-components.pdf (20)

PPTX
Table and Form HTML&CSS
PPTX
5. Php MongoDB vederea unui singur document
PPTX
Lecture-4.pptx
PDF
Vaadin Components @ Angular U
DOCX
Table through php
PPTX
01 HTML-Tables-1.pptx
PDF
Html cheat sheet
PPTX
HTML Tables and Forms
PPTX
Unit 1wt
PPTX
6. Php MongoDB adaugarea unui document
PPTX
Unit 1wt
PDF
Html Help Sheet 02
 
PDF
Creating web api and consuming part 2
PDF
Practicals it
PPTX
Html - Tables, Forms and Frames by Telerik Academy
PDF
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
DOC
Ôn tập KTTMDT
DOCX
table html web programing
PDF
The Ring programming language version 1.2 book - Part 33 of 84
PDF
The Ring programming language version 1.6 book - Part 47 of 189
Table and Form HTML&CSS
5. Php MongoDB vederea unui singur document
Lecture-4.pptx
Vaadin Components @ Angular U
Table through php
01 HTML-Tables-1.pptx
Html cheat sheet
HTML Tables and Forms
Unit 1wt
6. Php MongoDB adaugarea unui document
Unit 1wt
Html Help Sheet 02
 
Creating web api and consuming part 2
Practicals it
Html - Tables, Forms and Frames by Telerik Academy
Side by Side - Scala and Java Adaptations of Martin Fowler’s Javascript Refac...
Ôn tập KTTMDT
table html web programing
The Ring programming language version 1.2 book - Part 33 of 84
The Ring programming language version 1.6 book - Part 47 of 189

More from NuttavutThongjor1 (20)

PDF
Modern DevOps Day 5.pdfModern DevOps Day 5.pdf
PDF
Modern DevOps Day 4.pdfModern DevOps Day 4.pdf
PDF
Modern DevOps Day 3.pdfModern DevOps Day 3.pdf
PDF
Modern DevOps Day 2.pdfModern DevOps Day 2.pdf
PDF
Modern DevOps Day 1.pdfModern DevOps Day 1.pdfModern DevOps Day 1.pdf
PDF
misc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdf
PDF
Nest.js Microservices (1).pdf Nest.js Microservices (1).pdfNest.js Microservi...
PDF
Nest.js Microservices.pdfNest.js Microservices.pdfNest.js Microservices.pdfNe...
PDF
GraphQL.pdfGraphQL.pdfGraphQL.pdfGraphQL.pdfGraphQL.pdfGraphQL.pdf
PDF
Nest.js RESTful API development.pdf Nest.js RESTful API development.pdf
PDF
Nest.js RESTful API development.pdfNest.js RESTful API development.pdf
PDF
Recap JavaScript and TypeScript.pdf Recap JavaScript and TypeScript.pdf
PDF
Next.js web development.pdfNext.js web development.pdfNext.js web development...
PDF
Next.js web development.pdfNext.js web development.pdfNext.js web development...
PDF
Fullstack Nest.js and Next.js.pdfFullstack Nest.js and Next.js.pdfFullstack N...
PDF
Recap JavaScript and TypeScript.pdf Recap JavaScript and TypeScript.pdf
PDF
Intro to Modern DevOps.pdfIntro to Modern DevOps.pdfIntro to Modern DevOps.pdf
PDF
10 วัฒนธรรมองค์กรของ DevOps.pdf10 วัฒนธรรมองค์กรของ DevOps.pdf
PDF
9 logging and monitoring.pdf 9 logging and monitoring.pdf
PDF
8 iac.pdf 8 iac.pdf8 iac.pdf8 iac.pdf8 iac.pdf8 iac.pdf8 iac.pdf
Modern DevOps Day 5.pdfModern DevOps Day 5.pdf
Modern DevOps Day 4.pdfModern DevOps Day 4.pdf
Modern DevOps Day 3.pdfModern DevOps Day 3.pdf
Modern DevOps Day 2.pdfModern DevOps Day 2.pdf
Modern DevOps Day 1.pdfModern DevOps Day 1.pdfModern DevOps Day 1.pdf
misc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdfmisc.pdf
Nest.js Microservices (1).pdf Nest.js Microservices (1).pdfNest.js Microservi...
Nest.js Microservices.pdfNest.js Microservices.pdfNest.js Microservices.pdfNe...
GraphQL.pdfGraphQL.pdfGraphQL.pdfGraphQL.pdfGraphQL.pdfGraphQL.pdf
Nest.js RESTful API development.pdf Nest.js RESTful API development.pdf
Nest.js RESTful API development.pdfNest.js RESTful API development.pdf
Recap JavaScript and TypeScript.pdf Recap JavaScript and TypeScript.pdf
Next.js web development.pdfNext.js web development.pdfNext.js web development...
Next.js web development.pdfNext.js web development.pdfNext.js web development...
Fullstack Nest.js and Next.js.pdfFullstack Nest.js and Next.js.pdfFullstack N...
Recap JavaScript and TypeScript.pdf Recap JavaScript and TypeScript.pdf
Intro to Modern DevOps.pdfIntro to Modern DevOps.pdfIntro to Modern DevOps.pdf
10 วัฒนธรรมองค์กรของ DevOps.pdf10 วัฒนธรรมองค์กรของ DevOps.pdf
9 logging and monitoring.pdf 9 logging and monitoring.pdf
8 iac.pdf 8 iac.pdf8 iac.pdf8 iac.pdf8 iac.pdf8 iac.pdf8 iac.pdf

Recently uploaded (20)

PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Presentation on HIE in infants and its manifestations
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Complications of Minimal Access Surgery at WLH
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
master seminar digital applications in india
PDF
Classroom Observation Tools for Teachers
A systematic review of self-coping strategies used by university students to ...
Presentation on HIE in infants and its manifestations
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cell Structure & Organelles in detailed.
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
O7-L3 Supply Chain Operations - ICLT Program
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
VCE English Exam - Section C Student Revision Booklet
Complications of Minimal Access Surgery at WLH
Anesthesia in Laparoscopic Surgery in India
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Pharma ospi slides which help in ospi learning
2.FourierTransform-ShortQuestionswithAnswers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Module 4: Burden of Disease Tutorial Slides S2 2025
Supply Chain Operations Speaking Notes -ICLT Program
master seminar digital applications in india
Classroom Observation Tools for Teachers

vue-components.pdf

  • 2. Babel Coder COMPONENTS <script setup lang="ts"> const { data: articles } = useFetch('/api/articles') </script> <template> <h1>Article List</h1> <table> <thead> <tr> <td>ID</td> <td>Title</td> <td>Excerpt</td> </tr> </thead> <tbody> <tr v-for="article of articles" :key="article.id" @click="console.log(article.id)"> <td>{{ article.id }}</td> <td>{{ article.title }}</td> <td>{{ article.excerpt }}</td> </tr> </tbody> </table> </template>
  • 3. Babel Coder COMPONENTS <script setup lang="ts"> const { data: articles } = useFetch('/api/articles') </script> <template> <ArticleList :articles="articles" /> </template> <script setup lang="ts"> interface Article { id: number title: string excerpt: string } const { articles } = de fi neProps<{ articles: Article[] | null }>() </script> <template> <h1>Article List</h1> <table> <thead> <tr> <td>ID</td> <td>Title</td> <td>Excerpt</td> </tr> </thead> <tbody> <tr v-for="article of articles" :key="article.id" @click="console.log(article.id)"> <td>{{ article.id }}</td> <td>{{ article.title }}</td> <td>{{ article.excerpt }}</td> </tr> </tbody> </table> </template> components/article/ArticleList.vue
  • 4. Babel Coder COMPONENTS <script setup lang="ts"> import type { Column } from '~/components/ui/UiDataTable.vue' import type { ArticleItem } from '~/server/api/articles.get' const { data: articles } = useFetch('/api/articles') const columns: Column<ArticleItem>[] = [ { name: 'ID', fi eld: 'id' }, { name: 'Title', fi eld: 'title' }, { name: 'Excerpt', fi eld: 'excerpt' }, ] </script> <template> <UiDataTable title="Article List" :columns="columns" :rows="articles" /> </template>
  • 5. Babel Coder COMPONENTS <script setup lang="ts" generic="T extends { id: number }"> export interface Column<Row> { name: string fi eld: keyof Row } interface Props { title: string columns: Column<T>[] rows: T[] | null } const { title, columns, rows } = de fi neProps<Props>() </script> <template> <h1>{{ title }}</h1> <table> <thead> <tr> <td v-for="column of columns" :key="column. fi eld"> {{ column.name }} </td> </tr> </thead> <tbody> <tr v-for="row of rows" :key="row.id" @click="console.log(row.id)"> <td v-for="column of columns" :key="column. fi eld"> {{ row[column. fi eld] }} </td> </tr> </tbody> </table> </template> components/ui/UiDataTable.vue
  • 6. Babel Coder DEFAULT VALUES <script setup lang="ts"> import type { Column } from '~/components/ui/UiDataTable.vue' import type { ArticleItem } from '~/server/api/articles.get' const columns: Column<ArticleItem>[] = [ { name: 'ID', fi eld: 'id' }, { name: 'Title', fi eld: 'title' }, { name: 'Excerpt', fi eld: 'excerpt' }, ] </script> <template> <UiDataTable :columns="columns" /> </template>
  • 7. Babel Coder DEFAULT VALUES <script setup lang="ts" generic="T extends { id: number }"> export interface Column<Row> { name: string fi eld: keyof Row } interface Props { title?: string columns: Column<T>[] rows?: T[] | null } const { title, columns, rows } = withDefaults(de fi neProps<Props>(), { title: 'Data Table', rows: () => [], }) </script> <template> <h1>{{ title }}</h1> <div v-if="rows?.length === 0"> No data found </div> <table v-else> <thead> <tr> <td v-for="column of columns" :key="column. fi eld"> {{ column.name }} </td> </tr> </thead> <tbody> <tr v-for="row of rows" :key="row.id" @click="console.log(row.id)"> <td v-for="column of columns" :key="column. fi eld"> {{ row[column. fi eld] }} </td> </tr> </tbody> </table> </template> components/ui/UiDataTable.vue
  • 8. Babel Coder EMIT <script setup lang="ts"> import type { Column } from '~/components/ui/UiDataTable.vue' import type { ArticleItem } from '~/server/api/articles.get' const { data: articles } = useFetch('/api/articles') const columns: Column<ArticleItem>[] = [ { name: 'ID', fi eld: 'id' }, { name: 'Title', fi eld: 'title' }, { name: 'Excerpt', fi eld: 'excerpt' }, ] </script> <template> <UiDataTable title="Article List" :columns="columns" :rows="articles" @change="console.log($event)" /> </template>
  • 9. Babel Coder EMIT <script setup lang="ts" generic="T extends { id: number }"> export interface Column<Row> { name: string fi eld: keyof Row } interface Props { title?: string columns: Column<T>[] rows?: T[] | null } const { title, columns, rows } = withDefaults(de fi neProps<Props>(), { title: 'Data Table', rows: () => [], }) const emit = de fi neEmits<{ (e: 'change', id: number): void }>() </script> <template> <h1>{{ title }}</h1> <div v-if="rows?.length === 0"> No data found </div> <table v-else> <thead> <tr> <td v-for="column of columns" :key="column. fi eld"> {{ column.name }} </td> </tr> </thead> <tbody> <tr v-for="row of rows" :key="row.id" @click="emit('change', row.id)"> <td v-for="column of columns" :key="column. fi eld"> {{ row[column. fi eld] }} </td> </tr> </tbody> </table> </template> components/ui/UiDataTable.vue
  • 10. Babel Coder SLOT <script setup lang="ts"> </script> <template> <header>Header</header> <p>Content</p> <footer>Footer</footer> </template> <script setup lang="ts"> </script> <template> <UiCard /> </template> components/ui/UiCard.vue
  • 11. Babel Coder DEFAULT SLOT <script setup lang="ts"> </script> <template> <header>Header</header> <p><slot /></p> <footer>Footer</footer> </template> <script setup lang="ts"> </script> <template> <UiCard>My Content</UiCard> </template> components/ui/UiCard.vue
  • 12. Babel Coder NAMED SLOT <script setup lang="ts"> </script> <template> <header><slot name="header" /></header> <p><slot /></p> <footer><slot name="footer" /></footer> </template> <script setup lang="ts"> </script> <template> <UiCard> <template #header> My Header </template> <template #default> My Content </template> <template #footer> My Footer </template> </UiCard> </template> components/ui/UiCard.vue My Content
  • 13. Babel Coder FALLBACK CONTENT <script setup lang="ts"> </script> <template> <header> <slot name="header"> Header </slot> </header> <p><slot>Content</slot></p> <footer> <slot name="header"> Footer </slot> </footer> </template> <script setup lang="ts"> </script> <template> <UiCard> <template #header> My Header </template> My Content <template #footer> My Footer </template> </UiCard> </template> components/ui/UiCard.vue