{{ greeting }}
``` ### Mental Model When reading Vue code, ask four questions: 1. **What values are reactive state?** → Look for `ref()` and `computed()` 2. **Which template elements use that state?** → Look for `{{ variable }}` and `v-model` 3. **Which functions change that state?** → Look for functions that modify `.value` 4. **Which computed values depend on that state?** → Look for `computed()` --- ## Reactive State with `ref` ### What is `ref`? `ref()` wraps a value so Vue can track changes to it. ```ts import { ref } from 'vue'; const count = ref(0); // reactive number const username = ref('alice'); // reactive string const isLoading = ref(false); // reactive boolean const items = ref{{ username }}
{{ 2 + 3 }}
{{ isLoading ? 'Loading...' : 'Done' }}
{{ items.length }} items
``` ### Conditional Rendering: `v-if` / `v-else` Show elements based on conditions: ```vue{{ error }}
No errors
Welcome, {{ username }}!
Please log in.
You typed: {{ email }}
``` - User types → `email` updates - Code changes `email` → input display updates ### Select Dropdown ```vue{{ props.name }} is {{ props.age }} years old.