Skip to content

Commit 974247f

Browse files
posvayyx990803
authored andcommitted
Add missing string handler in v-for (#4499)
Fix #4497
1 parent 34333ca commit 974247f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/core/instance/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export function renderMixin (Vue: Class<Component>) {
178178
render: () => VNode
179179
): ?Array<VNode> {
180180
let ret: ?Array<VNode>, i, l, keys, key
181-
if (Array.isArray(val)) {
181+
if (Array.isArray(val) || typeof val === 'string') {
182182
ret = new Array(val.length)
183183
for (i = 0, l = val.length; i < l; i++) {
184184
ret[i] = render(val[i], i)

test/unit/features/directives/for.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,4 +428,22 @@ describe('Directive v-for', () => {
428428
expect(vm.$el.textContent).toMatch(/\s+foo\s+bar\s+/)
429429
}).then(done)
430430
})
431+
432+
it('strings', done => {
433+
const vm = new Vue({
434+
data: {
435+
text: 'foo'
436+
},
437+
template: `
438+
<div>
439+
<span v-for="letter in text">{{ letter }}.</span
440+
</div>
441+
`
442+
}).$mount()
443+
expect(vm.$el.textContent).toMatch('f.o.o.')
444+
vm.text += 'bar'
445+
waitForUpdate(() => {
446+
expect(vm.$el.textContent).toMatch('f.o.o.b.a.r.')
447+
}).then(done)
448+
})
431449
})

0 commit comments

Comments
 (0)