File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
test/unit/features/global-api Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ export function defineReactive (
189189 * already exist.
190190 */
191191export 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 ) ) ) {
193193 target . length = Math . max ( target . length , key )
194194 target . splice ( key , 1 , val )
195195 return val
Original file line number Diff line number Diff line change @@ -96,5 +96,23 @@ describe('Global API: set/delete', () => {
9696 expect ( vm . $el . innerHTML ) . toBe ( '' )
9797 } ) . then ( done )
9898 } )
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+ } )
99117 } )
100118} )
You can’t perform that action at this time.
0 commit comments