Skip to content

Commit 2f3510a

Browse files
authored
Update componentVModel.ts
1 parent 00b7822 commit 2f3510a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ShapeFlags, extend } 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,19 +29,18 @@ 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 model = (type as any).model || {}
42-
const mixins = (type as any).mixins
43-
mixins && mixins.forEach((m: any) => m.model && extend(model, m.model))
42+
const model = comp.model || {}
43+
applyModelFromMixins(model, comp.mixins)
4444
const { prop = 'value', event = 'input' } = model
4545
if (prop !== 'modelValue') {
4646
props[prop] = props.modelValue
@@ -55,6 +55,15 @@ export function convertLegacyVModelProps(vnode: VNode) {
5555
}
5656
}
5757

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+
5867
export function compatModelEmit(
5968
instance: ComponentInternalInstance,
6069
event: string,

0 commit comments

Comments
 (0)