1. Vue2
1) 오늘 배운 내용
예를 들어, 환경설정 옵션값이 true/false 에 따라,
특정 input값이 비어있다면 '설정해주세요'라는 메시지 팝업을 띄운다고 하자.
if ((this.place === null || this.place === '') && this.isRequiredInputPlace) {
this.$commonFunction.showDialog_alert_message('장소를 입력해주세요.');
}
컴파일러가 코드를 읽을 때
true || 면 그냥 true라고 인식해버림.
false && 면 그냥 false라고 인식해버림.
조건이 여러개일 때, 기준을 옵션값에 맞춰주면
if (this.isRequiredInputPlace && (this.place === null || this.place === '')) {
this.$commonFunction.showDialog_alert_message('장소를 입력해주세요.');
}
동작하는 건 똑같지만, 메모리 관리 관점에서 좀 더 효율적이다.
'코딩 > Javascript' 카테고리의 다른 글
[TIL - 2024.01.03] Vue.js $on $off (0) | 2024.01.03 |
---|---|
[TIL - 24.01.03] Vue.js / $nextTick() (0) | 2024.01.03 |
[TIL - 23.12.04] 자바스크립트 정규식 input에 번호만 입력(하이픈 추가) (0) | 2023.12.04 |
[TIL - 2023.11.23] find와 filter 차이 (0) | 2023.11.23 |
[JavaScript/Vue 2] - param 데이터 전달 (0) | 2023.11.09 |