Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- mariadb
- PostgreSQL
- Partition
- SSE
- 성장기
- Lag
- node.js
- localStorage
- Node.js기본
- 파티셔닝
- frontend
- EventSource
- 개발자
- ServerSentEvent
- 열공하자
- node.js란
- partitioning
- 실시간알림
Archives
- Today
- Total
써치킴의 우당탕탕 개발 블로그
[Vue.js][Ch2][Vue 문법] Watch 본문
Watch
데이터의 변경사항을 감시하는 용도
계산된 데이터도 감시할 수 있다.
<template>
<h1
@click="changeMessage">
{{ msg }}
</h1>
<h1>{{ reversedMessage }}</h1>
</template>
<script>
export default {
data() {
return {
msg: 'Hello?'
}
},
// msg가 바뀌면 계산된 데이터도 바뀐다.
computed: {
reversedMessage() {
return this.msg.split('').reverse().join('');
}
},
watch: {
// msg: function() { 와 같음
msg(newVal) { // msg라는 데이터는 감시되고 있는 상황, newVal은 변경된 값
console.log('msg', this.msg); // 감시되는 내용
console.log(newVal); // this.msg대신에 newVal을 사용할 수 있음
},
// computed를 통해 계산된 데이터도 감시할 수 있다.
reversedMessage() {
console.log('reversedMessage', this.reversedMessage);
}
},
methods: {
changeMessage() {
this.msg = 'Good!'
}
}
}
</script>
클릭 전
클릭 후
'완벽하게 Vue.js' 카테고리의 다른 글
[Vue.js][Ch2][Vue 문법] 조건부 렌더링 (0) | 2022.04.04 |
---|---|
[Vue.js][Ch2][Vue 문법] 클래스와 스타일 바인딩 (0) | 2022.03.02 |
[Vue.js][Ch2][Vue 문법] Getter, Setter (0) | 2022.03.01 |
[Vue.js][Ch2][Vue 문법] Computed 캐싱 (0) | 2022.03.01 |
[Vue.js][Ch2][Vue 문법] Computed (0) | 2022.03.01 |
Comments