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
  • Vue Composition API คืออะไร
  • ตัวอย่างการใช้งาน

Was this helpful?

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

Composition API

Vue Composition API คืออะไร

Vue Composition API เป็น API สำหรับการเขียนส่วนประกอบใน Vue ที่ทำให้การจัดการกับสถานะ (state) และ logic ของ component มีความยืดหยุ่น และสามารถนำกลับมาใช้ซ้ำได้ง่ายมากยิ่งขึ้น

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

<template>
  <div>
    <p>Count: {{ count }}</p>
    <button @click="increment">Increment</button>
  </div>
</template>

<script>
import { ref } from 'vue';

export default {
  setup() {
    const count = ref(0);

    function increment() {
      count.value++;
    }

    return {
      count,
      increment
    };
  }
};
</script>
PreviousGlobal APINextSingle-File Component (SFC)

Last updated 4 months ago

Was this helpful?

ในตัวอย่างนี้ เราใช้ เพื่อสร้างตัวแปร reactive และ สำหรับกำหนดว่า Vue ควรส่งคืนอะไรให้ template ซึ่งช่วยให้การจัดการและแยก logic ออกมาเป็นสัดส่วนได้ง่ายขึ้น.

📖
🌐
ref
setup