mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 01:52:19 +08:00
fix(vue): improve v-model binding sync between vue wrappers and web components (#22745)
resolves #22731
This commit is contained in:
@ -48,13 +48,15 @@ export const defineContainer = <Props>(name: string, componentProps: string[] =
|
||||
* They refer to whatever properties are set on an instance of a component.
|
||||
*/
|
||||
const Container = defineComponent<Props & InputProps>((props, { attrs, slots, emit }) => {
|
||||
let modelPropValue = (props as any)[modelProp];
|
||||
const containerRef = ref<HTMLElement>();
|
||||
const classes = new Set(getComponentClasses(attrs.class));
|
||||
const onVnodeBeforeMount = (vnode: VNode) => {
|
||||
// Add a listener to tell Vue to update the v-model
|
||||
if (vnode.el) {
|
||||
vnode.el.addEventListener(modelUpdateEvent.toLowerCase(), (e: Event) => {
|
||||
emit(UPDATE_VALUE_EVENT, (e?.target as any)[modelProp]);
|
||||
modelPropValue = (e?.target as any)[modelProp];
|
||||
emit(UPDATE_VALUE_EVENT, modelPropValue);
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -105,7 +107,7 @@ export const defineContainer = <Props>(name: string, componentProps: string[] =
|
||||
if (modelProp) {
|
||||
propsToAdd = {
|
||||
...propsToAdd,
|
||||
[modelProp]: props.hasOwnProperty('modelValue') ? props.modelValue : (props as any)[modelProp]
|
||||
[modelProp]: props.hasOwnProperty('modelValue') ? props.modelValue : modelPropValue
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user