Vue · Junior · Question 13 of 75

How do you declare reactive state in <script setup>?

const count = ref(0);
function increment() {
  count.value++;
}

Explanation

ref wraps a value in an object with a reactive .value property. Top-level refs are automatically unwrapped in templates, so you write {{ count }}.

Further reading

Problem with a question

Vue · Junior · question 13

Test yourself

Take the Vue · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz