Add missing string handler in v-for (#4499)

Fix #4497
This commit is contained in:
Eduardo San Martin Morote 2016-12-16 17:50:53 +01:00 committed by Evan You
parent 34333caa8c
commit 974247fd8e
2 changed files with 19 additions and 1 deletions

View File

@ -178,7 +178,7 @@ export function renderMixin (Vue: Class<Component>) {
render: () => VNode
): ?Array<VNode> {
let ret: ?Array<VNode>, i, l, keys, key
if (Array.isArray(val)) {
if (Array.isArray(val) || typeof val === 'string') {
ret = new Array(val.length)
for (i = 0, l = val.length; i < l; i++) {
ret[i] = render(val[i], i)

View File

@ -428,4 +428,22 @@ describe('Directive v-for', () => {
expect(vm.$el.textContent).toMatch(/\s+foo\s+bar\s+/)
}).then(done)
})
it('strings', done => {
const vm = new Vue({
data: {
text: 'foo'
},
template: `
<div>
<span v-for="letter in text">{{ letter }}.</span
</div>
`
}).$mount()
expect(vm.$el.textContent).toMatch('f.o.o.')
vm.text += 'bar'
waitForUpdate(() => {
expect(vm.$el.textContent).toMatch('f.o.o.b.a.r.')
}).then(done)
})
})