Vue 3·Vue from reactivity to a routed app

Setup and reactivity

Create a Vue app and make state reactive with ref and reactive.

Intermediate 12 min read Lesson 1 of 300 Challenge included
What you will be able to do
  • Mount an app with createApp.
  • Use ref for primitives and arrays you replace.
  • Use reactive for grouped object state.
  • Write logic in a setup script, not in global variables.

In plain English

Vue tracks reads and writes so the DOM updates when state changes. ref wraps a single value and exposes it through .value in JavaScript; templates unwrap it automatically. Keep state as local as possible.

App.vueJavaScript
<script setup>
import { ref } from 'vue'

const count = ref(0)
const increment = () => count.value++
</script>

<template>
  <button @click="increment">Clicked {{ count }} times</button>
</template>
Your turn

Add a reset button

Easy

Add a button that sets the count back to zero.

JAVASCRIPT · starter
const reset = () => { }
Check your understanding before moving on.
Knowledge checkQuestion 1

How do you read a ref value inside a script?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Template syntax
Lesson 1 of 300 · 0% of course