fix(v-memo): should work on v-for with constant expression (#4272)
fix #4246
This commit is contained in:
parent
c421fb91b2
commit
3b60358d0e
@ -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>`)
|
||||
})
|
||||
})
|
||||
|
@ -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]) {
|
||||
|
Loading…
Reference in New Issue
Block a user