fix(v-once): fix v-once usage with v-if and v-for

fix #2035
This commit is contained in:
Evan You
2020-09-02 12:29:07 -04:00
parent ad93fa42fc
commit 52e45a9850
4 changed files with 77 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
import { createApp, ref, nextTick } from '../src'
import { createApp, ref, nextTick, reactive } from '../src'
describe('compiler + runtime integration', () => {
it('should support runtime template compilation', () => {
@@ -247,4 +247,38 @@ describe('compiler + runtime integration', () => {
document.querySelector = origin
})
test('v-if + v-once', async () => {
const ok = ref(true)
const App = {
setup() {
return { ok }
},
template: `<div>{{ ok }}<div v-if="ok" v-once>{{ ok }}</div></div>`
}
const container = document.createElement('div')
createApp(App).mount(container)
expect(container.innerHTML).toBe(`<div>true<div>true</div></div>`)
ok.value = false
await nextTick()
expect(container.innerHTML).toBe(`<div>false<div>true</div></div>`)
})
test('v-for + v-once', async () => {
const list = reactive([1])
const App = {
setup() {
return { list }
},
template: `<div>{{ list.length }}<div v-for="i in list" v-once>{{ i }}</div></div>`
}
const container = document.createElement('div')
createApp(App).mount(container)
expect(container.innerHTML).toBe(`<div>1<div>1</div></div>`)
list.push(2)
await nextTick()
expect(container.innerHTML).toBe(`<div>2<div>1</div></div>`)
})
})