IT/JavaScript
[JAVASCRIPT] 자식컴포넌트에서 부모로 사용시 뒤로가기
@욕심쟁이
2021. 9. 30. 11:57
반응형
부모의 자식컴포넌트에서 뒤로가기 시 아래 코드를 사용하면 부모로 이동 가능
<html>
<!-- 여기는 부모 -->
<!-- 자식컴포넌트 -->
<AdServiceDetail v-if="serviceDetail" @goList="serviceDetail = false"/>
</html>
<script>
// vue는 mounted에 설정
// react는 useEffect(() => {
// console.log('마운트 될 때만 실행됩니다.');
// }, []);
let serviceDetail = false
//or serviceDetail : false
// vue는 mounted에 설정
window.addEventListener('popstate', (e)=>{
console.log("POPSTATE CHANGED")
if(this.serviceDetail){
this.serviceDetail = false;
this.$router.go(1)
}
})
</script>
반응형