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
- 성장기
- 개발자
- localStorage
- 파티셔닝
- node.js
- SSE
- Node.js기본
- 실시간알림
- frontend
- Lag
- node.js란
- ServerSentEvent
- EventSource
- 열공하자
- mariadb
- PostgreSQL
- partitioning
- Partition
Archives
- Today
- Total
써치킴의 우당탕탕 개발 블로그
[Vue.js][Ch2][Vue 문법] Computed 캐싱 본문
<template>
<h1>{{ msg + '??' }}</h1>
<h1>{{ msg.split('').reverse().join('') }}</h1>
<h1>{{ msg.split('').reverse().join('') }}</h1>
<h1>{{ msg.split('').reverse().join('') }}</h1>
<h1>{{ msg.split('').reverse().join('') }}</h1>
</template>
<script>
export default {
data() {
return {
msg: 'Hello Computed!'
}
}
}
</script>
<h1>{{ msg.split('').reverse().join('') }}</h1> 를 반복 선언하는 건 비효율적이다.
<template>
<h1>{{ msg + '??' }}</h1>
<h1>{{ reverseMessage() }}</h1>
<h1>{{ reverseMessage() }}</h1>
<h1>{{ reverseMessage() }}</h1>
<h1>{{ reverseMessage() }}</h1>
</template>
<script>
export default {
data() {
return {
msg: 'Hello Computed!'
}
},
methods: {
reverseMessage() {
return this.msg.split('').reverse().join('');
}
}
}
</script>
method를 사용해서 대체할 수도 있지만, 마찬가지로 함수를 계속 실행되어야 한다.
=> 로직이 네번을 반복 동작하는 것은 똑같다.
<template>
<h1>{{ msg + '??' }}</h1>
<h1>{{ reversedMessage }}</h1>
<h1>{{ reversedMessage }}</h1>
<h1>{{ reversedMessage }}</h1>
<h1>{{ reversedMessage }}</h1>
</template>
<script>
export default {
data() {
return {
msg: 'Hello Computed!'
}
},
computed: {
// 메소드처럼 만들었지만 계산된 데이터이다.
reversedMessage() {
return this.msg.split('').reverse().join('');
}
},
methods: {
reverseMessage() {
return this.msg.split('').reverse().join('');
}
}
}
</script>
computed는 캐싱이라는 기능이 있기 때문에 한번 연산된 값은 다시 연산하지 않는다.
=> 반복 사용에 부담이 적다.

'완벽하게 Vue.js' 카테고리의 다른 글
[Vue.js][Ch2][Vue 문법] Watch (0) | 2022.03.01 |
---|---|
[Vue.js][Ch2][Vue 문법] Getter, Setter (0) | 2022.03.01 |
[Vue.js][Ch2][Vue 문법] Computed (0) | 2022.03.01 |
[Vue.js][Ch2][Vue 문법] 템플릿 문법 (0) | 2022.02.28 |
[Vue.js][Ch2][Vue 문법] 인스턴스와 라이프사이클 (0) | 2022.02.28 |
Comments