fix(v-memo): should work on v-for with constant expression (#4272)

fix #4246
This commit is contained in:
edison 2021-08-07 09:37:09 +08:00 committed by GitHub
parent c421fb91b2
commit 3b60358d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -147,4 +147,26 @@ describe('v-memo', () => {
`<div>5 yes z</div><div>2 no z</div><div>3 no z</div>`
)
})
test('on v-for /w constant expression ', async () => {
const [el, vm] = mount({
template: `<div v-for="item in 3" v-memo="[count < 2 ? true : count]">
{{count}}
</div>`,
data: () => ({
count: 0
})
})
expect(el.innerHTML).toBe(`<div>0</div><div>0</div><div>0</div>`)
vm.count = 1
await nextTick()
// should not update
expect(el.innerHTML).toBe(`<div>0</div><div>0</div><div>0</div>`)
vm.count = 2
await nextTick()
// should update
expect(el.innerHTML).toBe(`<div>2</div><div>2</div><div>2</div>`)
})
})

View File

@ -71,7 +71,7 @@ export function renderList(
}
ret = new Array(source)
for (let i = 0; i < source; i++) {
ret[i] = renderItem(i + 1, i)
ret[i] = renderItem(i + 1, i, undefined, cached && cached[i])
}
} else if (isObject(source)) {
if (source[Symbol.iterator as any]) {