Skip to content
Grok

Overview

Single File Components (SFCs) เป็นไฟล์ .vue ที่ประกอบด้วยสามส่วนหลัก:

Single File Components

รูปแบบการเขียน Vue Component ในไฟล์ .vue เดียวที่รวม template, script และ style

FeatureDescriptionCategory
vuejs.org favicon<template>กำหนด markup ของ componentTemplate
vuejs.org favicon<script>กำหนด logic ของ componentScript
vuejs.org favicon<script setup>Composition API syntaxScript
vuejs.org favicon<style>กำหนด styles สำหรับ componentStyle
vuejs.org faviconscopedจำกัด scope ของ stylesStyle
vuejs.org faviconmoduleCSS ModulesStyle
vuejs.org faviconv-bind()ใช้ค่าจาก script ใน CSSStyle

script setup

Syntax พิเศษสำหรับการใช้ Composition API ใน SFC

Featureคำอธิบายลิงค์เอกสาร
defineProps()ประกาศ props ของ componentvuejs.org favicondefineProps
defineEmits()ประกาศ custom eventsvuejs.org favicondefineEmits
defineModel()สองทาง binding สำหรับ propsvuejs.org favicondefineModel
defineExpose()เปิดเผย properties ให้ parent componentvuejs.org favicondefineExpose
defineOptions()ประกาศ component optionsvuejs.org favicondefineOptions
defineSlots()ประกาศ slot typesvuejs.org favicondefineSlots
useSlots()ใช้งาน slots ใน scriptvuejs.org faviconuseSlots
useAttrs()ใช้งาน attributes ใน scriptvuejs.org faviconuseAttrs
<script setup>Composition API syntax sugarvuejs.org faviconscript setup docs
Top-level awaitใช้ async/await ได้โดยตรงvuejs.org faviconTop-level await

CSS Features

คุณสมบัติพิเศษของ CSS ใน SFC เช่น scoped styles และ CSS Modules

Featureคำอธิบายลิงค์เอกสาร
<style scoped>Scoped CSSvuejs.org faviconScoped CSS
<style module>CSS Modules syntaxvuejs.org faviconCSS Modules
v-bind() in CSSใช้ reactive values ใน CSSvuejs.org faviconv-bind in CSS