Vue First SFC Web Page
🌟 Vue First SFC Web Page (Single File Component) Web Page
An SFC keeps HTML, JavaScript, and CSS together in one .vue file.
What is a Vue SFC?
A Single File Component is a .vue file that contains:
✔ Clean
✔ Organized
✔ Scalable
✔ Industry standard
🧱 Step 1: Create a Vue Project (Using Vite)
Run this in terminal:
Then:
Open browser at:
👉 http://localhost:5173
🧩 Step 2: Understand Default Structure
🧠 Step 3: main.js (Entry Point)
✔ Loads App.vue
✔ Mounts app to index.html
🧩 Step 4: Your First SFC – App.vue
This is your first Vue SFC web page 👇
What’s Happening Here?
🧩 <template>
✔ Displays dynamic data
✔ Uses Vue template syntax
🧠 <script>
✔ Holds logic & state
✔ methods handle events
🎨 <style>
✔ Styles your component
🔒 Scoped Style (Recommended)
✔ CSS applies only to this component
🧩 Step 5: Create Another SFC Component
📄 src/components/Home.vue
Use it in App.vue:
Why SFC is Best for Real Projects
| Feature | Benefit |
|---|---|
| Single file | Easy maintenance |
| Scoped CSS | No style conflicts |
| Reusable | Component-based |
| Tooling | IDE & build support |
❌ Common Beginner Mistakes
❌ Forgetting export default
❌ Writing logic in <template>
❌ Not using scoped styles
❌ Large components (split them)
✅ Best Practices
✔ One component = one responsibility
✔ Keep SFC under control
✔ Use components folder
✔ Use scoped styles
✔ Move logic to composables later
🏁 Conclusion
Your first Vue SFC web page is now ready 🎉
Single File Components are the backbone of professional Vue applications.
