Adding Reactivity Using Ref
Learn how to add reactivity using ref.
We'll cover the following...
Reactive objects like these are great if we have multiple values, such as our user
and darkMode
values:
Press + to interact
<script setup>let state = reactive({user: null,darkMode: false,});</script>
What about simple, primitive values such as a number or a string of text?
Press + to interact
<script setup>const user = 'Bob'const age = 32</script>
Creating a reactive object with ref
We know that any updates to our variables will not cause the data inside the template to update. This may cause issues if, for example, the user make ...