Created
June 17, 2021 17:15
-
-
Save guillaumeduhan/2aa618f68a133613ddfee3ffce1c38fe to your computer and use it in GitHub Desktop.
Vue 3: watch
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
<template> | |
<div> | |
<input v-model="name" /> | |
<p>{{ msg }}</p> | |
</div> | |
</template> | |
<script> | |
import { reactive, toRefs, computed, watch } from "vue"; | |
export default { | |
setup () { | |
const data = reactive({ | |
name: 'Guillaume', | |
msg: computed(() => { | |
return `Hello ${data.name}` | |
}) | |
}); | |
watch(() => data.msg, (newValue, oldValue) => { | |
console.log(newValue) | |
console.log(oldValue) | |
}); | |
return { | |
...toRefs(data) | |
}; | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment