πΒ Reference
πΒ Chapter
ref
, reactive
, computed
μ κ°μ λ°μν μνκ° λ³κ²½λ λλ§λ€ μ€νλλ€.source
)μ μ΄μ κ°κ³Ό μλ‘μ΄ κ°μ μ½λ°± ν¨μμ μΈμλ‘ μ 곡νλ€.import { ref, watch } from 'vue';
// 1. κ°μν λ°μν λ°μ΄ν°
const count = ref(0);
// 2. watch ν¨μ μ μ
watch(
// κ°μ λμ (Source)
count,
// μ½λ°± ν¨μ (Callback)
(newValue, oldValue) => {
console.log(`countκ° ${oldValue}μμ ${newValue}λ‘ λ³κ²½λμμ΅λλ€.`);
// μ΄κ³³μμ API νΈμΆ, λΉλκΈ° λ‘μ§, κΈ°ν λΆμ ν¨κ³Ό λ±μ μ²λ¦¬ν©λλ€.
}
);
count.value = 1; // π‘ watch μ½λ°± ν¨μ μ€ν