Skip to main content
Vue is a progressive framework for building user interfaces. It is designed to be incrementally adoptable and scalable.
  1. 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 provides ref, reactive, computed, and watch.
  1. ref creates a reactive primitive value.
  2. reactive creates a reactive object.
[!WARNING] reactive vs ref Unlike ref, which requires you to append .value, reactive properties are accessed directly, making the code cleaner.
  1. computed creates a derived reactive value.
  1. watch runs a side-effect function when a reactive source changes.
  1. shallowRef is typically used for performance optimizations of large data structures that don’t require deep reactivity.
Check Reactivity API: Core and Reactivity API: Advanced.

Template Syntax

Vue directives are special attributes with v- prefix that apply reactive behavior to the DOM.
  1. v-bind can spread multiple props from one object. : is shorthand for v-bind: btw.
  1. Similarly, v-on can attach multiple listeners from one object, and @ is shorthand for v-on:.

Dynamic components

Use this pattern for tabs, widget renderers, or configurable UI blocks.
More about Built-in Special Elements.

Async Components

Async components are loaded on demand, which can improve performance for large apps and reduce initial bundle size.

Props

  1. defineProps is the recommended way to declare props.
Check Props and Typing Component Props.

Emits

  1. defineEmits is the recommended way to declare emitted events.
[!WARNING] Emits are used to for child-to-parent communication. They allow a child component to send a custom event with optional data payload up to its parent component

Models

  1. defineModel is used for building two-way component bindings.
[!WARNING] Parent usage

Expose

  1. defineExpose controls what methods//properties 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 these attributes will become attributes of input.
props will not be forwarded to the inner element.

Slots

  1. <slot> is used inside a child component to declare insertion points.
  2. v-slot is used in the parent when providing content to named//scoped slots. # is shorthand for v-slot:.
  1. You can destructure slot props as well.
  1. Use the $slots property with a v-if to achieve Conditional Slots.
Check Slots.

Template Refs

  1. Template Refs: There may be cases where we need direct access to the underlying DOM elements. To achieve this, we can use the special ref attribute.
  2. To obtain the reference with Composition API, we can use the useTemplateRef() helper.

Composables

  1. Composables are Vue-aware functions that use reactive APIs//lifecycle hooks.
  2. Utils are 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.
  1. Use toValue() or toRef() to normalize them. Reactivity API: Utilities
Check Utility Types.
[!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.
  1. 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.
  1. Avoid a single giant global store. Instead, create multiple small stores focused on specific domains or features.