
[Vue.js] tutorial - 10. Watchers
·
✏️ Study/⛰️ Vue.js & Nuxt
📍watch- watchers를 사용하면 사이드 이펙트를 반응적으로 수행할 수 있다- 예) 특정 값이 바뀌면 콘솔에 숫자 출력하기import { ref, watch } from 'vue'const count = ref(0)watch(count, (newCount) => { // yes, console.log() is a side effect console.log(`new count is: ${newCount}`)})- 위 예시에서 count의 값이 바뀌면 콜백 함수가 실행된다- ref 말고도 다른 타입의 데이터를 watch가 감지하게 할 수 있다- 예시 Todo id: {{ todoId }} Fetch next todo Loading... {{ todoData }}