javascript / beginner
Snippet
Reactive Objects with reactive()
While ref() is used for single values, reactive() is used to make an entire object reactive. You don't need .value to access properties.
snippet.js
javascript
1
2
3
4
5
6
7
8
9
10
import { reactive } from 'vue';const userProfile = reactive({name: 'Alex',level: 1});function updateName(newName) {userProfile.name = newName;}
vue
Breakdown
1
const userProfile = reactive({
Creates a reactive state object that Vue tracks for changes.
2
userProfile.name = newName;
Updates the property directly without needing a .value suffix.