Frontend
[vue3] lifecycle hook
어코링
2024. 11. 10. 17:21
beforeCreate()
created()
beforeMount() : mount 되기 전에 실행 함수
mounted() : mount 된 이후
beforeUpdate()
updated()
beforeUnmount()
unmounted()
등등 lifecycle hook 종류 다양하다
*자바스크립트 문법 setTimeout
setTimeout(function() {
실행할 코드
}, 2000);
여기서 2000는 2초 뒤
// mount된 이후
mounted() {
setTimeout(() => {
this.showDiscount = false;
}, 2000)
arrow ()=>{} 를 사용하면 this 값을 가져올수있음
서버에서 데이터 가져올때도 lifecycle hook 안에 코드 작성
created(){서버에서 가져오는 코드 }와 mounted() {서버에서 가져오는 코드 } hook 함수는 ajax요청에 활용