Skip to content

Commit f50a034

Browse files
authored
Update back-button.ts
vue自动注销事件
1 parent 3f8346e commit f50a034

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/vue/src/hooks/back-button.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { BackButtonEvent } from "@ionic/core/components";
2+
import { onBeforeUnmount, getCurrentInstance } from 'vue'
23

34
type Handler = (processNextHandler: () => void) => Promise<any> | void | null;
45
export interface UseBackButtonResult {
@@ -15,6 +16,12 @@ export const useBackButton = (
1516
document.removeEventListener("ionBackButton", callback);
1617

1718
document.addEventListener("ionBackButton", callback);
19+
20+
if (getCurrentInstance()){
21+
onBeforeUnmount(() => {
22+
unregister()
23+
});
24+
}
1825

1926
return { unregister };
2027
};

0 commit comments

Comments
 (0)