Back to Home
    Vue.jsVue.js v3.5Beginner

    Vue.js

    Vue 3 Composition API, reactivity, components, directives, and Pinia state management.

    10 min read
    vuefrontendjavascriptcomposition-api

    Composition API

    1 topic

    ref & reactive

    vue
    <script setup lang="ts">
    import { ref, reactive, computed, watch } from "vue";
    
    // ref: for primitives
    const count = ref(0);
    const name = ref("Alice");
    count.value++;  // Access with .value in script
    
    // reactive: for objects
    const user = reactive({ name: "Alice", age: 30 });
    user.age++;  // No .value needed
    
    // computed
    const doubled = computed(() => count.value * 2);
    const fullName = computed(() => `${user.name} ${user.last}`);
    
    // watch
    watch(count, (newVal, oldVal) => {
      console.log(`${oldVal} → ${newVal}`);
    });
    
    // watchEffect (auto-tracks dependencies)
    watchEffect(() => {
      document.title = `Count: ${count.value}`;
    });
    </script>

    💡 Use ref for primitives, reactive for objects

    ⚡ watchEffect is great when you want to auto-track without listing dependencies

    Template Directives

    1 topic

    Common Directives

    vue
    <template>
      <!-- Bind value -->
      <input :value="name" />
      <img :src="imgUrl" :alt="imgAlt" />
    
      <!-- Two-way bind -->
      <input v-model="name" />
    
      <!-- Conditional -->
      <div v-if="isAdmin">Admin panel</div>
      <div v-else-if="isUser">User view</div>
      <div v-else>Guest</div>
    
      <!-- Show/hide (keeps DOM) -->
      <div v-show="isVisible">Content</div>
    
      <!-- List rendering -->
      <ul>
        <li v-for="item in items" :key="item.id">
          {{ item.name }}
        </li>
      </ul>
    
      <!-- Event handling -->
      <button @click="handleClick">Click</button>
      <form @submit.prevent="handleSubmit">...</form>
    </template>

    ⚠️ Always use :key with v-for — use a unique ID, not the array index

    💡 v-show is better than v-if for elements that toggle frequently

    Related Articles

    Background reading and deeper explanations for this sheet.

    AI Product Pricing Strategies: How to Monetize for Growth, Margin, and Customer Trust

    Pricing an AI product is not just a finance decision—it shapes adoption, retention, margins, and user trust. In this practical guide, you’ll learn how to choose the right pricing model, align price with value and costs, and avoid common mistakes using real-world examples and implementation frameworks.

    keyword overlap

    Build an Agentic App with FastAPI and Azure AI Foundry: A Practical Beginner-to-Pro Guide

    Learn how to design, build, and deploy an agentic application using FastAPI and Azure AI Foundry with practical, real-world examples. This guide walks you from architecture and setup to tool-calling, memory, observability, and production deployment patterns.

    keyword overlap

    FastAPI Interview Questions: Practical Cheat Sheet for Developers

    Preparing for FastAPI interviews can feel overwhelming if you only memorize definitions. This practical cheat sheet helps you answer common FastAPI interview questions with confidence using real-world examples, production-ready patterns, and beginner-friendly explanations with depth.

    keyword overlap

    GenAI SaaS Architecture: A Practical Blueprint for Building, Scaling, and Securing AI Products

    Designing a SaaS product on top of GenAI is more than calling an LLM API—it requires thoughtful architecture across product, data, safety, and operations. This practical guide walks you through a beginner-friendly yet deep system blueprint, with real-world patterns, code snippets, and deployment strategies you can use immediately.

    keyword overlap