{{ message }}
``` ## Python Analogy Think of a Vue component like a Python object plus a small HTML view. Python-style thinking: ```python class CounterPage: def __init__(self): self.message = "Hello from Vue" self.count = 0 def increment(self): self.count += 1 ``` Vue-style thinking: ```ts const message = 'Hello from Vue'; const count = ref(0); function increment() { count.value += 1; } ``` Difference: - In Python, changing `self.count` changes object state. - In Vue, changing `count.value` changes reactive state and the UI updates automatically. ## What "Reactive" Means Reactive means the UI watches data. When the data changes, Vue updates the screen. Example: ```vue{{ name }}
``` When `name.value` changes, the paragraph updates. ## Template vs Script The template is not plain HTML. It is HTML with Vue features. Example: ```vue{{ username }}
``` - `{{ username }}` means: print a variable into the HTML. - `@click="login"` means: run the function when clicked. The script defines the variables and functions used by the template. ```ts ``` ## Common Vue Building Blocks ### `ref` Used for reactive single values. ```ts const count = ref(0); const username = ref('alice'); const isLoading = ref(false); ``` ### `computed` Used for values derived from other values. ```ts const firstName = ref('Ada'); const lastName = ref('Lovelace'); const fullName = computed(() => `${firstName.value} ${lastName.value}`); ``` ### event handlers Functions triggered by user actions. ```vue ``` ```ts function save() { console.log('saving'); } ``` ### lifecycle hooks Code that runs when a component starts. ```ts onMounted(async () => { await loadData(); }); ``` This is roughly like running setup code after the component appears on screen. ## `v-model` in One Sentence `v-model` is two-way binding between a form field and a reactive variable. ```vue ``` If the user types into the input, `username` changes. If `username` changes in code, the input display changes. ## Example: Filter Form ```vue ``` This is very similar to your date filter selects in FlexibilityTable. ## Good Beginner Rule When reading Vue code, ask these four questions: 1. What values are reactive state? 2. Which template elements use that state? 3. Which functions change that state? 4. Which computed values or API calls depend on that state? If you answer those four, most Vue components become understandable. ## Related Notes - [[01-Refs, Computed, and Reactivity]] - [[02-Templates, v-model, and Events]] - [[03-Components, Props, Lifecycle, and Composables]] - [[04-FlexibilityTable Filter Flow]]