File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed
Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -124,15 +124,17 @@ function checkIfWeCanLeavePage() {
124124 return wasSaveSuccessful .value || cancelButtonClicked .value || JSON .stringify (record .value ) === JSON .stringify (initialValues .value );
125125}
126126
127- window . addEventListener ( ' beforeunload ' , (event ) => {
127+ function onBeforeUnload (event : BeforeUnloadEvent ) {
128128 if (! checkIfWeCanLeavePage ()) {
129129 event .preventDefault ();
130130 event .returnValue = ' ' ;
131131 }
132- });
132+ }
133+
134+ window .addEventListener (' beforeunload' , onBeforeUnload );
133135
134136onBeforeUnmount (() => {
135- window .removeEventListener (' beforeunload' , () => {} );
137+ window .removeEventListener (' beforeunload' , onBeforeUnload );
136138});
137139
138140onBeforeRouteLeave (async (to , from , next ) => {
Original file line number Diff line number Diff line change @@ -105,19 +105,21 @@ const initialRecord = computed(() => coreStore.record);
105105const wasSaveSuccessful = ref (false );
106106const cancelButtonClicked = ref (false );
107107
108- function checkIfWeCanLeavePage() {
109- return wasSaveSuccessful .value || cancelButtonClicked .value || JSON .stringify (record .value ) === JSON .stringify (initialRecord .value );
110- }
111-
112- window .addEventListener (' beforeunload' , (event ) => {
108+ function onBeforeUnload(event : BeforeUnloadEvent ) {
113109 if (! checkIfWeCanLeavePage ()) {
114110 event .preventDefault ();
115111 event .returnValue = ' ' ;
116112 }
117- });
113+ }
114+
115+ function checkIfWeCanLeavePage() {
116+ return wasSaveSuccessful .value || cancelButtonClicked .value || JSON .stringify (record .value ) === JSON .stringify (initialRecord .value );
117+ }
118+
119+ window .addEventListener (' beforeunload' , onBeforeUnload );
118120
119121onBeforeUnmount (() => {
120- window .removeEventListener (' beforeunload' , () => {} );
122+ window .removeEventListener (' beforeunload' , onBeforeUnload );
121123});
122124
123125onBeforeRouteLeave (async (to , from , next ) => {
You can’t perform that action at this time.
0 commit comments