fix(vue): improve v-model integration for Vue 3.1.0+ (#23420)

This commit is contained in:
Liam DeBeasi
2021-06-04 19:25:02 -04:00
committed by GitHub
parent 82cfa55653
commit f008628851
3 changed files with 17 additions and 9 deletions

View File

@ -121,9 +121,17 @@ export const defineContainer = <Props>(name: string, componentProps: string[] =
};
if (modelProp) {
/**
* Starting in Vue 3.1.0, all properties are
* added as keys to the props object, even if
* they are not being used. In order to correctly
* account for both value props and v-model props,
* we need to check if the key exists for Vue <3.1.0
* and then check if it is not undefined for Vue >= 3.1.0.
*/
propsToAdd = {
...propsToAdd,
[modelProp]: props.hasOwnProperty('modelValue') ? props.modelValue : modelPropValue
[modelProp]: props.hasOwnProperty(MODEL_VALUE) && props[MODEL_VALUE] !== undefined ? props.modelValue : modelPropValue
}
}