@@ -32,7 +32,7 @@ export default {
32
32
}
33
33
}
34
34
if ( vnode . tag === 'select' ) {
35
- setSelected ( el , binding . value )
35
+ setSelected ( el , binding , vnode . context )
36
36
} else {
37
37
if ( ! isAndroid ) {
38
38
el . addEventListener ( 'compositionstart' , onCompositionStart )
@@ -45,27 +45,36 @@ export default {
45
45
}
46
46
} ,
47
47
componentUpdated ( el , binding , vnode ) {
48
- const val = binding . value
49
48
if ( vnode . tag === 'select' ) {
50
- setSelected ( el , val )
49
+ setSelected ( el , binding , vnode . context )
51
50
// in case the options rendered by v-for have changed,
52
51
// it's possible that the value is out-of-sync with the rendered options.
53
52
// detect such cases and filter out values that no longer has a matchig
54
53
// option in the DOM.
55
54
const needReset = el . multiple
56
- ? val . some ( v => hasNoMatchingOption ( v , el . options ) )
57
- : hasNoMatchingOption ( val , el . options )
55
+ ? binding . value . some ( v => hasNoMatchingOption ( v , el . options ) )
56
+ : hasNoMatchingOption ( binding . value , el . options )
58
57
if ( needReset ) {
59
58
trigger ( el , 'change' )
60
59
}
61
60
}
62
61
}
63
62
}
64
63
65
- function setSelected ( el , value ) {
64
+ function setSelected ( el , binding , vm ) {
65
+ const value = binding . value
66
66
const isMultiple = el . multiple
67
67
if ( ! isMultiple ) {
68
68
el . selectedIndex = - 1
69
+ } else if ( ! Array . isArray ( value ) ) {
70
+ process . env . NODE_ENV !== 'production' && warn (
71
+ `<select multiple v-model="${ binding . expression } "> ` +
72
+ `expects an Array value for its binding, but got ${
73
+ Object . prototype . toString . call ( value ) . slice ( 8 , - 1 )
74
+ } `,
75
+ vm
76
+ )
77
+ return
69
78
}
70
79
for ( let i = 0 , l = el . options . length ; i < l ; i ++ ) {
71
80
const option = el . options [ i ]
0 commit comments