mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-15 17:42:15 +08:00
fix(vue): ionChange events now propagate correctly (#22872)
resolves #22870
This commit is contained in:
@ -2,8 +2,17 @@ import { App, Plugin } from 'vue';
|
||||
import { IonicConfig, setupConfig } from '@ionic/core';
|
||||
import { applyPolyfills, defineCustomElements } from '@ionic/core/loader';
|
||||
|
||||
const ael = (el: any, eventName: string, cb: any, opts: any) => el.addEventListener(eventName.toLowerCase(), cb, opts);
|
||||
const rel = (el: any, eventName: string, cb: any, opts: any) => el.removeEventListener(eventName.toLowerCase(), cb, opts);
|
||||
/**
|
||||
* We need to make sure that the web component fires an event
|
||||
* that will not conflict with the user's @ionChange binding,
|
||||
* otherwise the binding's callback will fire before any
|
||||
* v-model values have been updated.
|
||||
*/
|
||||
const transformEventName = (eventName: string) => {
|
||||
return eventName === 'ionChange' ? 'v-ionchange' : eventName.toLowerCase();
|
||||
}
|
||||
const ael = (el: any, eventName: string, cb: any, opts: any) => el.addEventListener(transformEventName(eventName), cb, opts);
|
||||
const rel = (el: any, eventName: string, cb: any, opts: any) => el.removeEventListener(transformEventName(eventName), cb, opts);
|
||||
|
||||
export const IonicVue: Plugin = {
|
||||
|
||||
@ -17,7 +26,7 @@ export const IonicVue: Plugin = {
|
||||
await applyPolyfills();
|
||||
await defineCustomElements(window, {
|
||||
exclude: ['ion-tabs'],
|
||||
ce: (eventName: string, opts: any) => new CustomEvent(eventName.toLowerCase(), opts),
|
||||
ce: (eventName: string, opts: any) => new CustomEvent(transformEventName(eventName), opts),
|
||||
ael,
|
||||
rel
|
||||
} as any);
|
||||
|
Reference in New Issue
Block a user