mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 01:52:19 +08:00
feat(vue): add composition API ionic lifecycle hooks (#22970)
resolves #22769
This commit is contained in:
@ -3,6 +3,19 @@ import { Config as CoreConfig, LIFECYCLE_DID_ENTER, LIFECYCLE_DID_LEAVE, LIFECYC
|
||||
|
||||
type LIFECYCLE_EVENTS = typeof LIFECYCLE_WILL_ENTER | typeof LIFECYCLE_DID_ENTER | typeof LIFECYCLE_WILL_LEAVE | typeof LIFECYCLE_DID_LEAVE;
|
||||
|
||||
export enum LifecycleHooks {
|
||||
WillEnter = 'onIonViewWillEnter',
|
||||
DidEnter = 'onIonViewDidEnter',
|
||||
WillLeave = 'onIonViewWillLeave',
|
||||
DidLeave = 'onIonViewDidLeave'
|
||||
}
|
||||
const hookNames = {
|
||||
[LIFECYCLE_WILL_ENTER]: LifecycleHooks.WillEnter,
|
||||
[LIFECYCLE_DID_ENTER]: LifecycleHooks.DidEnter,
|
||||
[LIFECYCLE_WILL_LEAVE]: LifecycleHooks.WillLeave,
|
||||
[LIFECYCLE_DID_LEAVE]: LifecycleHooks.DidLeave
|
||||
}
|
||||
|
||||
const ids: { [k: string]: number } = { main: 0 };
|
||||
|
||||
export const generateId = (type = 'main') => {
|
||||
@ -21,6 +34,18 @@ export const fireLifecycle = (vueComponent: any, vueInstance: Ref<ComponentPubli
|
||||
if (instance?.[lifecycle]) {
|
||||
instance[lifecycle]();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire any Composition API
|
||||
* Ionic Lifecycle hooks
|
||||
*/
|
||||
if (instance) {
|
||||
const hook = hookNames[lifecycle];
|
||||
const hooks = instance[hook];
|
||||
if (hooks) {
|
||||
hooks.forEach((hook: Function) => hook());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const getConfig = (): CoreConfig | null => {
|
||||
|
Reference in New Issue
Block a user