ウォッチャー
概要
ウォッチャーを使用することで値を監視してコールバックを発行することができる。
import { ref, watch } from 'vue'
const count = ref(0)
watch(count, (newCount) => {
console.log(`new count is: ${newCount}`)
})watch()は、直接refであるcountを監視して、その値が変化するたびにwatchブロック内のコードが実行される。
1 分で読めます
ウォッチャーを使用することで値を監視してコールバックを発行することができる。
import { ref, watch } from 'vue'
const count = ref(0)
watch(count, (newCount) => {
console.log(`new count is: ${newCount}`)
})watch()は、直接refであるcountを監視して、その値が変化するたびにwatchブロック内のコードが実行される。