mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
fix(vue): modal, popover, and nav are now created within application context (#22282)
resolves #22079
This commit is contained in:
38
packages/vue/src/components/IonApp.ts
Normal file
38
packages/vue/src/components/IonApp.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { h, defineComponent, shallowRef, VNode } from 'vue';
|
||||
|
||||
const userComponents = shallowRef([]);
|
||||
export const IonApp = defineComponent({
|
||||
name: 'IonApp',
|
||||
setup(_, { attrs, slots }) {
|
||||
return () => {
|
||||
return h(
|
||||
'ion-app',
|
||||
{
|
||||
...attrs
|
||||
},
|
||||
[slots.default && slots.default(), ...userComponents.value]
|
||||
)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* When rendering user components inside of
|
||||
* ion-modal, ion-popover, or ion-nav, the component
|
||||
* needs to be created inside of the current application
|
||||
* context otherwise libraries such as vue-i18n or vuex
|
||||
* will not work properly.
|
||||
*
|
||||
* `userComponents` renders teleported components as children
|
||||
* of `ion-app` within the current application context.
|
||||
*/
|
||||
export const addTeleportedUserComponent = (component: VNode) => {
|
||||
userComponents.value = [
|
||||
...userComponents.value,
|
||||
component
|
||||
]
|
||||
}
|
||||
|
||||
export const removeTeleportedUserComponent = (component: VNode) => {
|
||||
userComponents.value = userComponents.value.filter(cmp => cmp !== component);
|
||||
}
|
Reference in New Issue
Block a user