Frameworks & Libraries
Vue.js Basics
Vue is a progressive JavaScript framework loved for its gentle learning curve, excellent documentation, and elegant reactivity system. Learn Single File Components, the Composition API, directives, and Pinia state management.
What is Vue.js?
Vue is a progressive JavaScript framework for building user interfaces. Single-file components (.vue) combine a template, script and styles. Reactive state from ref() and reactive() updates the DOM automatically. Vue is known for a gentle learning curve and clear documentation, and Nuxt is its full-stack framework.
<script setup>
import { ref, computed } from "vue";
const count = ref(0);
const double = computed(() => count.value * 2);
</script>
<template>
<button @click="count++">{{ count }} (double: {{ double }})</button>
</template>React vs Vue — Quick Reference
| Concept | React | Vue 3 |
|---|---|---|
Local state | useState() | ref() / reactive() |
Derived value | useMemo() | computed() |
Side effects | useEffect() | watch() / watchEffect() |
Two-way binding | value + onChange | v-model |
Conditional | Ternary / && | v-if / v-else / v-show |
Lists | .map() + key prop | v-for + :key |
Events | onClick={fn} | @click="fn" |
Lifecycle (mount) | useEffect(fn, []) | onMounted(fn) |
Global state | Redux / Zustand | Pinia |
Routing | React Router | Vue Router |
Custom hooks | Custom hooks (use...) | Composables (use...) |
Styling | CSS modules / styled | scoped CSS in .vue |
Common Pitfalls
Forgetting .value when accessing ref() in script — ref.count++ instead of ref.value++
Only in templates does Vue auto-unwrap refs. In <script setup>, always use count.value
Using v-if and v-for on the same element — v-for takes priority in Vue 2, causing unexpected behavior
Wrap the v-if in a parent <template> tag: <template v-if='show'><li v-for='...'>
Mutating props directly in a child component — Vue warns and it breaks data flow
Emit an event to the parent: emit('update:value', newVal). The parent updates its own state.
Destructuring reactive() objects breaks reactivity: const { name } = reactive(state)
Use toRefs() to destructure reactively: const { name } = toRefs(state)
Vue Code Examples
Code Editor
<div id="app">
<input v-model="name" placeholder="Your name">
<p>Hello, {{ name || "stranger" }}!</p>
<button @click="count++">Clicked {{ count }} times (double: {{ double }})</button>
<ul><li v-for="t in todos" :key="t">{{ t }}</li></ul>
</div>Preview
Vue Basics: summary
Key points
refvalues are read and written with.valuein script, but used directly in templates.- Directives:
v-if,v-for,v-model(two-way binding),@event,:prop. computedcaches derived values;watchruns side effects when data changes.
Frequently asked questions
›Vue or React?
Both are excellent. React has the bigger job market and ecosystem; Vue has a gentler learning curve and more built-in conventions. Either is fine as a first framework.