Dark mode
คําแนะนําในการพัฒนา Vue.js
การจัดการโครงสร้างโปรเจค
- ใช้ Vue CLI หรือ Vite ในการสร้างโปรเจค เพื่อให้ได้โครงสร้างที่เป็นมาตรฐาน
- จัดเรียงไฟล์ให้เป็นระเบียบตาม feature หรือ component
- แยก components, views, และ assets ให้เป็นหมวดหมู่
การเขียน Component
- ใช้ Composition API สําหรับโปรเจคใหม่
- แยก component ให้มีขนาดเล็กและทํางานเฉพาะอย่าง
- ตั้งชื่อ component ให้สื่อความหมายและใช้ PascalCase
- หลีกเลี่ยงการเขียน logic ที่ซับซ้อนใน template
การจัดการ State
- ใช้ Pinia สําหรับการจัดการ state ขนาดใหญ่
- ใช้ ref() สําหรับค่าเดี่ยว และ reactive() สําหรับ object
- หลีกเลี่ยงการใช้ global state เมื่อไม่จําเป็น
Performance
- ใช้ v-show แทน v-if เมื่อต้องการซ่อน/แสดงบ่อยๆ
- ใช้ computed properties แทนการคํานวณใน template
- ระวังการใช้ watch ที่อาจทําให้เกิด infinite loop
- ใช้ lazy loading สําหรับ components ที่ไม่จําเป็นต้องโหลดทันที
TypeScript
- ใช้ TypeScript เพื่อเพิ่มความปลอดภัยของ code
- กําหนด type ให้กับ props และ emits
- ใช้ interface สําหรับกําหนด shape ของ data
Testing
- เขียน unit test สําหรับ components สําคัญ
- ใช้ Vitest หรือ Jest สําหรับการทดสอบ
- ทดสอบ user interactions และ state changes
Best Practices
- ใช้ ESLint และ Prettier เพื่อรักษามาตรฐานโค้ด
- เขียน documentation สําหรับ components ที่ซับซ้อน
- ใช้ environment variables สําหรับค่า configuration
- อัพเดท dependencies อย่างสม่ําเสมอ
Security
- ป้องกัน XSS ด้วยการใช้ v-html อย่างระมัดระวัง
- ตรวจสอบ input data ทั้งฝั่ง client และ server
- ใช้ HTTPS สําหรับการสื่อสารกับ API
Optimization
- ใช้ production build เมื่อ deploy
- optimize รูปภาพและ assets
- ใช้ CDN สําหรับ static content
- implement caching strategy ที่เหมาะสม