Front-end/JavaScript
특정 날짜의 요일 구하기, 가격 컴마 표기
byolee
2020. 5. 15. 10:54
getDay(date){
const week = ['일', '월', '화', '수', '목', '금', '토'];
return week[new Date(date).getDay()];
}
vue에서 사용한 코드
<td>{{code.startdate}} ({{getDay(code.startdate)}})</td>
v-for을 사용하여 렌더링할 때 함수 파라미터에 날짜를 넣어주고 요일 리턴
Vue.filter('toPrice', price => {
if (price === 0) return '무료'
else return price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '원'
})
vue filter를 이용해서 price를 파라미터로 받아 세자리마다 컴마를 추가해주는 데이터로 리턴