Skip to content

Commit 72130ac

Browse files
authored
fix(compat): convertLegacyVModelProps should merge model option in mixins (#5251)
1 parent 92e04a6 commit 72130ac

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

packages/runtime-core/src/compat/componentVModel.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ShapeFlags } from '@vue/shared'
1+
import { extend, ShapeFlags } from '@vue/shared'
22
import { ComponentInternalInstance, ComponentOptions } from '../component'
33
import { callWithErrorHandling, ErrorCodes } from '../errorHandling'
44
import { VNode } from '../vnode'
@@ -15,6 +15,7 @@ const warnedTypes = new WeakSet()
1515

1616
export function convertLegacyVModelProps(vnode: VNode) {
1717
const { type, shapeFlag, props, dynamicProps } = vnode
18+
const comp = type as ComponentOptions
1819
if (shapeFlag & ShapeFlags.COMPONENT && props && 'modelValue' in props) {
1920
if (
2021
!isCompatEnabled(
@@ -28,17 +29,19 @@ export function convertLegacyVModelProps(vnode: VNode) {
2829
return
2930
}
3031

31-
if (__DEV__ && !warnedTypes.has(type as ComponentOptions)) {
32+
if (__DEV__ && !warnedTypes.has(comp)) {
3233
pushWarningContext(vnode)
33-
warnDeprecation(DeprecationTypes.COMPONENT_V_MODEL, { type } as any, type)
34+
warnDeprecation(DeprecationTypes.COMPONENT_V_MODEL, { type } as any, comp)
3435
popWarningContext()
35-
warnedTypes.add(type as ComponentOptions)
36+
warnedTypes.add(comp)
3637
}
3738

3839
// v3 compiled model code -> v2 compat props
3940
// modelValue -> value
4041
// onUpdate:modelValue -> onModelCompat:input
41-
const { prop = 'value', event = 'input' } = (type as any).model || {}
42+
const model = comp.model || {}
43+
applyModelFromMixins(model, comp.mixins)
44+
const { prop = 'value', event = 'input' } = model
4245
if (prop !== 'modelValue') {
4346
props[prop] = props.modelValue
4447
delete props.modelValue
@@ -52,6 +55,15 @@ export function convertLegacyVModelProps(vnode: VNode) {
5255
}
5356
}
5457

58+
function applyModelFromMixins(model: any, mixins?: ComponentOptions[]) {
59+
if (mixins) {
60+
mixins.forEach(m => {
61+
if (m.model) extend(model, m.model)
62+
if (m.mixins) applyModelFromMixins(model, m.mixins)
63+
})
64+
}
65+
}
66+
5567
export function compatModelEmit(
5668
instance: ComponentInternalInstance,
5769
event: string,

0 commit comments

Comments
 (0)