A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/vuejs/vue/commit/8a2c514 below:

Be able to use string type index in array (#5889) · vuejs/vue@8a2c514 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+19

-1

lines changed

Filter options

Expand file treeCollapse 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 (

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4