1
- import { ShapeFlags } from '@vue/shared'
1
+ import { extend , ShapeFlags } from '@vue/shared'
2
2
import { ComponentInternalInstance , ComponentOptions } from '../component'
3
3
import { callWithErrorHandling , ErrorCodes } from '../errorHandling'
4
4
import { VNode } from '../vnode'
@@ -15,6 +15,7 @@ const warnedTypes = new WeakSet()
15
15
16
16
export function convertLegacyVModelProps ( vnode : VNode ) {
17
17
const { type, shapeFlag, props, dynamicProps } = vnode
18
+ const comp = type as ComponentOptions
18
19
if ( shapeFlag & ShapeFlags . COMPONENT && props && 'modelValue' in props ) {
19
20
if (
20
21
! isCompatEnabled (
@@ -28,17 +29,19 @@ export function convertLegacyVModelProps(vnode: VNode) {
28
29
return
29
30
}
30
31
31
- if ( __DEV__ && ! warnedTypes . has ( type as ComponentOptions ) ) {
32
+ if ( __DEV__ && ! warnedTypes . has ( comp ) ) {
32
33
pushWarningContext ( vnode )
33
- warnDeprecation ( DeprecationTypes . COMPONENT_V_MODEL , { type } as any , type )
34
+ warnDeprecation ( DeprecationTypes . COMPONENT_V_MODEL , { type } as any , comp )
34
35
popWarningContext ( )
35
- warnedTypes . add ( type as ComponentOptions )
36
+ warnedTypes . add ( comp )
36
37
}
37
38
38
39
// v3 compiled model code -> v2 compat props
39
40
// modelValue -> value
40
41
// 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
42
45
if ( prop !== 'modelValue' ) {
43
46
props [ prop ] = props . modelValue
44
47
delete props . modelValue
@@ -52,6 +55,15 @@ export function convertLegacyVModelProps(vnode: VNode) {
52
55
}
53
56
}
54
57
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
+
55
67
export function compatModelEmit (
56
68
instance : ComponentInternalInstance ,
57
69
event : string ,
0 commit comments