- Basically, it does the same thing as React but better.
Vue SFC Basics
Most Vue apps use Single File Components.Reactivity Essentials
For reactivity, Vue providesref, reactive, computed, and watch.
refcreates a reactive primitive value.reactivecreates a reactive object.
[!WARNING]reactivevsrefUnlikeref, which requires you to append.value,reactiveproperties are accessed directly, making the code cleaner.
computedcreates a derived reactive value.
watchruns a side-effect function when a reactive source changes.- Learn more about Watchers.
shallowRefis typically used for performance optimizations of large data structures that don’t require deep reactivity.
Template Syntax
Vue directives are special attributes withv- prefix that apply reactive behavior to the DOM.
v-bindcan spread multiple props from one object.:is shorthand forv-bind:btw.
- Similarly,
v-oncan attach multiple listeners from one object, and@is shorthand forv-on:.
Dynamic components
Use this pattern for tabs, widget renderers, or configurable UI blocks.Async Components
Async components are loaded on demand, which can improve performance for large apps and reduce initial bundle size.Props
definePropsis the recommended way to declare props.
Emits
defineEmitsis the recommended way to declare emitted events.
[!WARNING] Emits are used to for child-to-parent communication. They allow achildcomponent to send a custom event with optional data payload up to itsparentcomponent
Models
defineModelis used for building two-way component bindings.
[!WARNING] Parent usage
Expose
defineExposecontrols what methodsproperties are accessible by the parent when using template refs.
Transparent Components
Transparent components are wrapper components that forward all parent-provided attributes and listeners to an inner element, bypassing the root element’s automatic attribute inheritance.[!WARNING] Parent usage All of theseattributeswill become attributes ofinput.propswill not be forwarded to the inner element.
Slots
<slot>is used inside a child component to declare insertion points.v-slotis used in the parent when providing content to namedscoped slots.#is shorthand forv-slot:.
- You can
destructureslot props as well.
- Use the
$slotsproperty with av-ifto achieve Conditional Slots.
Template Refs
-
Template Refs: There may be cases where we need direct access to the underlying DOM elements. To achieve this, we can use the special
refattribute. -
To obtain the reference with Composition API, we can use the
useTemplateRef()helper.
Composables
- Composables are Vue-aware functions that use reactive APIslifecycle hooks.
Utilsare plain framework-agnostic functions (formatters, parsers, helpers, etc.)
[!WARNING] Flexible Composable Inputs Try to keep composable arguments flexible by accepting static values, refs, or getters.
- Use
toValue()ortoRef()to normalize them. Reactivity API: Utilities
[!TIP] A simple alternative to a full state management library for small features.
Singleton shared state can be implemented with a composable that holds reactive state.
Routing
Vue Router is the official router for Vue.js.File-based routing
File-based routing maps file paths to routes automatically, common in Nuxt. You can use it in Vue with unplugin-vue-router.- It generates typed routes from your file structure and gives type-safe navigation.
VueUse
VueUse is a collection of high-quality composables.State Management
You can use composables for simple shared state, but for larger apps, a state management library like Pinia is recommended.- Avoid a single giant global store. Instead, create multiple small stores focused on specific domains or features.