728x90
반응형
글자 잘라내기 : substr()
날짜 계산하기 : parseInt(toDay.getFullYear())
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>데이터 사용</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "app2">
<hr>
<p>이름 : {{myName}}, 주민번호 : {{myBirth}}</p>
<p>{{myName}}님. 반갑습니다.<br>
당신의 생일은<br>
{{myBirth.substr(2,2)}}월 {{myBirth.substr(4,2)}}일.<br>
나이는<br>
{{(parseInt(toDay.getFullYear())) - (parseInt(myBirth.substr(0,2)) + 1900) +1 }}세 이군요.
</p>
<hr>
</div>
<script>
var app2 = new Vue({
el: '#app2',
data: {
myName: prompt('이름을 입력하세요', '홍길동'),
myBirth: prompt('주민번호를 입력하세요', '123456-1234567'),
toDay: new Date()
}
})
</script>
</body>
</html>
728x90
반응형