Vue.js Cheatsheet - API Reference
This reference targets Vue 3 developers working with the Composition API and <script setup>. It walks from reactivity basics (ref vs reactive) to computed and watchers, then props/emits/provide-inject for component communication, before covering routing, Pinia, templates, and performance tweaks like shallowRef and defineAsyncComponent. Each entry is a snippet you can drop into an existing SFC and observe the reactive update. After reading you should be able to manage local state with ref/reactive, react to changes with watch, wire up a child parent call, and lazy-load heavy components.
Reactivity Basics 8
const count = ref(0)count.value++const state = reactive({ name: "Vue" })const doubled = computed(() => count.value * 2)const w = computed({ get: () => v.value, set: (x) => (v.value = x) })watch(count, (n, o) => {}, { immediate: true })watchEffect(() => console.log(count.value))const { name } = toRefs(state)Lifecycle Hooks 6
onBeforeMount(() => {})onMounted(() => {})onBeforeUpdate(() => {})onUpdated(() => {})onBeforeUnmount(() => {})onUnmounted(() => {})Component Communication 6
defineProps<{ msg: string }>()const emit = defineEmits(["change"])defineExpose({ method() {} })provide("theme", "dark")const theme = inject("theme", "light")const model = defineModel<string>()Composables 5
function useCounter(n = 0) { const c = ref(n); return { c, inc: () => c.value++ } }const { c, inc } = useCounter(10)function useMouse() { const x = ref(0); const y = ref(0); return { x, y } }function useEventListener(el, ev, cb) { onUnmounted(() => el.removeEventListener(ev, cb)) }function useFetch(url) { /* return { data, error, loading } */ }Router & State 7
const route = useRoute()const router = useRouter()router.push("/users")router.replace("/login")const store = useCounterStore()const { count } = storeToRefs(store)store.$patch({ count: 1 })Template Syntax 8
{{ message }}:href="url"@click="handler"v-model="form.name"v-if / v-else-if / v-elsev-for="item in list" :key="item.id"<Teleport to="body"><slot name="header" />Performance 6
const list = shallowRef([])markRaw(obj)v-memo="[a, b]"defineAsyncComponent(() => import("./Comp.vue"))<KeepAlive include="UserList"><Suspense>Tips
- ref is for primitives, reactive for objects; ref needs .value in script but auto-unwraps in templates.
- computed caches and recomputes only on dependency change; watch is lazy unless immediate: true.
- defineProps/Emits/Expose/Model are compiler macros - no import needed.
- Destructuring a reactive object loses reactivity; wrap with toRefs first.
- Use shallowRef + v-memo for big lists, defineAsyncComponent for route components.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us