사용자가 입력하는 화면에서 실수로 뒤로가기/새로고침을 눌렀을 때
사용자 편의성을 위해 확인창을 한번 실행해준다.
자바스크립트로 하는 방법도 있지만, 나는 Vue.js로 작업하고 있는 페이지여서
Vue.js로 만들었다.
mounted() {
window.addEventListener('beforeunload', this.unLoadEvent);
},
beforeUnmount() {
window.removeEventListener('beforeunload', this.unLoadEvent);
},
methods: {
unLoadEvent: function (event) {
if (this.isLeaveSite) return;
event.preventDefault();
event.returnValue = '';
},
}
참고 블로그: https://88240.tistory.com/530
728x90
'ETC > Vue.js' 카테고리의 다른 글
Vue select value 가져오기 @change / event.target.value (0) | 2023.02.15 |
---|---|
v-show 조건부 랜더링 (0) | 2022.12.28 |
v-on 이벤트 처리 (0) | 2022.12.23 |
Vue.js DB 엔터값 줄바꿈 css style 태그로 초간단 출력하게 하기 (0) | 2022.12.21 |
v-bind + 이벤트 핸들링 정리잘하신 블로그 (1) | 2022.12.21 |
댓글