File tree 2 files changed +19
-1
lines changed
test/unit/features/global-api
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ export function defineReactive (
189
189
* already exist.
190
190
*/
191
191
export function set ( target : Array < any > | Object , key : any , val : any ) : any {
192
- if ( Array . isArray ( target ) && typeof key === 'number' ) {
192
+ if ( Array . isArray ( target ) && ( typeof key === 'number' || / ^ \d + $ / . test ( key ) ) ) {
193
193
target . length = Math . max ( target . length , key )
194
194
target . splice ( key , 1 , val )
195
195
return val
Original file line number Diff line number Diff line change @@ -96,5 +96,23 @@ describe('Global API: set/delete', () => {
96
96
expect ( vm . $el . innerHTML ) . toBe ( '' )
97
97
} ) . then ( done )
98
98
} )
99
+
100
+ it ( 'be able to use string type index in array' , done => {
101
+ const vm = new Vue ( {
102
+ template : '<div><p v-for="obj in lists">{{obj.name}}</p></div>' ,
103
+ data : {
104
+ lists : [
105
+ { name : 'A' } ,
106
+ { name : 'B' } ,
107
+ { name : 'C' }
108
+ ]
109
+ }
110
+ } ) . $mount ( )
111
+ expect ( vm . $el . innerHTML ) . toBe ( '<p>A</p><p>B</p><p>C</p>' )
112
+ Vue . set ( vm . lists , '0' , { name : 'D' } )
113
+ waitForUpdate ( ( ) => {
114
+ expect ( vm . $el . innerHTML ) . toBe ( '<p>D</p><p>B</p><p>C</p>' )
115
+ } ) . then ( done )
116
+ } )
99
117
} )
100
118
} )
You can’t perform that action at this time.
0 commit comments