GSP.DEV
  • about
    • ✌️ สวัสดีครับ 😊
  • ⬜introduction
    • 🌐Web Development
      • 🖼️Frontend Developer
      • 🖥️Backend Developer
      • 🎓Full Stack Developer
      • 🚀DevOps Engineer
  • 📖Software
    • 🌐Web Development
      • Language
        • Javascript
        • TypeScript
        • PHP
        • Python
      • Runtime
        • Javascript Runtime
          • Node.js
          • Bun
      • Frontend Framework
        • CSS Framework
          • Tailwind CSS
        • Vite
        • Vue.js
          • Global API
          • Composition API
          • Single-File Component (SFC)
        • Nuxt.js
        • React.js
          • ตัวอย่างการใช้งาน React JS
        • Next.js
      • Backend Framework
        • Express.js
        • NestJS
        • Laravel
    • 🖥️Opeating System
      • Linux
        • Debian
        • Ubuntu
    • 📚Database
      • Relational Databases
        • MySQL
        • Postgres
      • Non-relational Database
        • Document
          • MongoDB
        • Key-value
          • Redis
        • Time Series
          • Prometheus
    • ⚙️Container
      • Docker
        • คำสั่ง Docker พื้นฐาน
      • LXC (Linux Containers)
        • การใช้งาน LXC
        • การใช้งาน Proxmox LXC
      • Container Runtime
        • Docker Container Runtime
        • Containerd
      • Container Orchestration
        • Docker Swarm
        • Kubernetes
    • 🛡️VPN
      • Wireguard
      • Tailscale
    • ☁️Serverless
      • Amazon S3 + Cloudfront
      • Vercel
      • Cloudflare Pages
      • AWS Lambda
    • 📦CDN
      • Cloudfront
    • 🗃️Storage
      • Amazon S3
      • MinIO
    • ✏️Content Management System
      • WordPress
    • 📷Photo Management Software
      • Immich
  • 🏭Infrastructure
    • 🌐Network
      • Firewall
      • Subnet
      • Router
      • Internet
      • Domain
      • DNS
      • Private Network
      • SDN
      • IPAM
      • Protocol
        • IP Address
        • DHCP
        • RTMP
        • TCP
        • UDP
        • HTTP
        • HTTPS
  • ⚙️Technology
    • Cloud Computing คืออะไร
    • VPN คืออะไร
    • Container
  • 🗣️เรื่องเล่า
    • การลดขนาด Image Docker
      • สำหรับ Next.js
    • รีวิว Github Copiot
  • 👨‍💻ลงโค้ด
    • Vue 3
      • การใช้งาน ref
      • การใช้งาน script setup
      • การใช้งาน await ใน script setup
Powered by GitBook
On this page

Was this helpful?

  1. Software
  2. Web Development
  3. Frontend Framework
  4. Vue.js

Single-File Component (SFC)

Vue Single-File Component คืออะไร

Vue Single-File Component (SFC) เป็นไฟล์ที่มีนามสกุล .vue ซึ่งรวมการเขียนโค้ดในรูปแบบ HTML, JavaScript และ CSS ไว้ในไฟล์เดียว เพื่อให้การพัฒนา Vue.js components เป็นระบบและจัดการได้ง่ายขึ้น โดยมีโครงสร้างหลักประกอบด้วยสามส่วน คือ <template>, <script> และ <style>.

ตัวอย่างการใช้

<template>
  <div class="greeting">
    <h1>{{ message }}</h1>
  </div>
</template>

<script>
export default {
  data() {
    return {
      message: 'Hello, Vue Single-File Component!'
    };
  }
};
</script>

<style scoped>
.greeting {
  font-family: Arial, sans-serif;
  text-align: center;
  color: #42b983;
}
</style>

ในตัวอย่างนี้เรามีไฟล์ SFC ที่กำหนดข้อความต้อนรับ และสไตล์เฉพาะในไฟล์เดียวกัน โดยที่ <style scoped> จะทำให้ CSS มีผลเฉพาะกับ component นี้เท่านั้น.

PreviousComposition APINextNuxt.js

Last updated 4 months ago

Was this helpful?

📖
🌐