컴포넌트의 lifecycle
- 우리가 만든 컴포넌트들은 웹페이지에 표시되기까지 일련의 step을 거침 그 step을 라이프사이클이라 함
- 서버에서 데이터 가져올 때도 lifecycle hook 안에 코드 짬(created() 사용 등)
<template> 사이에 있던 걸 실제 HTML로 바꿔줌ex) 컴포넌트가 mount 되기 전에 해당 코드 실행
ex) 컴포넌트가 update(재렌더링)되기 전에 해당 코드 실행
ex) create 되기 전에 해당 코드 실행
export default {
data(){// 데이터 보관통
return {
showDiscount: true,
}
},
}
export default {
name: 'App',
mounted(){ //mount 후에 실행
setTimeout(() => {
this.showDiscount = false;
}, 200)
}
}
<span v-if="showDiscount">사라진다</span>
// showDiscount는 true임
beforeCreate()
created()
beforeMount()
mounted()
beforeUpdate()
updated()
beforeUnmount()
unmounted()
등