Created
February 7, 2025 14:42
-
-
Save Kcko/da6f13bde273c9b772f39b28e690605b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup> | |
import { shallowRef, watchEffect, triggerRef } from 'vue' | |
const user = shallowRef({ | |
name: 'John', | |
job: 'BFU', | |
age: 90 | |
}) | |
// Log the user whenever it changes | |
watchEffect(() => { | |
console.log('LOG: watchEffect', user) | |
}); | |
// Update nested state (no log happens) | |
setTimeout(() => { | |
user.value.name = 'Martin'; | |
console.log('LOG: user name changed') | |
}, 2000) | |
// Force a reactive update to trigger | |
setTimeout(() => { | |
triggerRef(user); | |
console.log('LOG: whole object changed') | |
}, 4000) | |
// [user object] | |
</script> | |
< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment