@@ -22,14 +22,7 @@ if (isIE9) {
22
22
export default {
23
23
inserted ( el , binding , vnode ) {
24
24
if ( vnode . tag === 'select' ) {
25
- const cb = ( ) => {
26
- setSelected ( el , binding , vnode . context )
27
- }
28
- cb ( )
29
- /* istanbul ignore if */
30
- if ( isIE || isEdge ) {
31
- setTimeout ( cb , 0 )
32
- }
25
+ setSelected ( el , binding , vnode . context )
33
26
el . _vOptions = [ ] . map . call ( el . options , getValue )
34
27
} else if ( vnode . tag === 'textarea' || isTextInputType ( el . type ) ) {
35
28
el . _vModifiers = binding . modifiers
@@ -67,37 +60,45 @@ export default {
67
60
}
68
61
69
62
function setSelected ( el , binding , vm ) {
70
- const value = binding . value
71
- const isMultiple = el . multiple
72
- if ( isMultiple && ! Array . isArray ( value ) ) {
73
- process . env . NODE_ENV !== 'production' && warn (
74
- `<select multiple v-model="${ binding . expression } "> ` +
75
- `expects an Array value for its binding, but got ${
76
- Object . prototype . toString . call ( value ) . slice ( 8 , - 1 )
77
- } `,
78
- vm
79
- )
80
- return
81
- }
82
- let selected , option
83
- for ( let i = 0 , l = el . options . length ; i < l ; i ++ ) {
84
- option = el . options [ i ]
85
- if ( isMultiple ) {
86
- selected = looseIndexOf ( value , getValue ( option ) ) > - 1
87
- if ( option . selected !== selected ) {
88
- option . selected = selected
89
- }
90
- } else {
91
- if ( looseEqual ( getValue ( option ) , value ) ) {
92
- if ( el . selectedIndex !== i ) {
93
- el . selectedIndex = i
63
+ const cb = ( ) => {
64
+ const value = binding . value
65
+ const isMultiple = el . multiple
66
+ if ( isMultiple && ! Array . isArray ( value ) ) {
67
+ process . env . NODE_ENV !== 'production' && warn (
68
+ `<select multiple v-model="${ binding . expression } "> ` +
69
+ `expects an Array value for its binding, but got ${
70
+ Object . prototype . toString . call ( value ) . slice ( 8 , - 1 )
71
+ } `,
72
+ vm
73
+ )
74
+ return
75
+ }
76
+ let selected , option
77
+ for ( let i = 0 , l = el . options . length ; i < l ; i ++ ) {
78
+ option = el . options [ i ]
79
+ if ( isMultiple ) {
80
+ selected = looseIndexOf ( value , getValue ( option ) ) > - 1
81
+ if ( option . selected !== selected ) {
82
+ option . selected = selected
83
+ }
84
+ } else {
85
+ if ( looseEqual ( getValue ( option ) , value ) ) {
86
+ if ( el . selectedIndex !== i ) {
87
+ el . selectedIndex = i
88
+ }
89
+ return
94
90
}
95
- return
96
91
}
97
92
}
93
+ if ( ! isMultiple ) {
94
+ el . selectedIndex = - 1
95
+ }
98
96
}
99
- if ( ! isMultiple ) {
100
- el . selectedIndex = - 1
97
+
98
+ cb ( )
99
+ /* istanbul ignore if */
100
+ if ( isIE || isEdge ) {
101
+ setTimeout ( cb , 0 )
101
102
}
102
103
}
103
104
0 commit comments