mirror of
https://gitee.com/vuejs/vue.git
synced 2024-11-30 19:17:40 +08:00
fix(keep-alive): run prune after render for correct active component check
fix #7566
This commit is contained in:
parent
4378fc5124
commit
215f877d1b
@ -71,13 +71,13 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
include (val: string | RegExp | Array<string>) {
|
||||
mounted () {
|
||||
this.$watch('include', val => {
|
||||
pruneCache(this, name => matches(val, name))
|
||||
},
|
||||
exclude (val: string | RegExp | Array<string>) {
|
||||
})
|
||||
this.$watch('exclude', val => {
|
||||
pruneCache(this, name => !matches(val, name))
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
render () {
|
||||
|
@ -393,6 +393,35 @@ describe('Component keep-alive', () => {
|
||||
}).then(done)
|
||||
})
|
||||
|
||||
it('prune cache on include/exclude change + view switch', done => {
|
||||
const vm = new Vue({
|
||||
template: `
|
||||
<div>
|
||||
<keep-alive :include="include">
|
||||
<component :is="view"></component>
|
||||
</keep-alive>
|
||||
</div>
|
||||
`,
|
||||
data: {
|
||||
view: 'one',
|
||||
include: 'one,two'
|
||||
},
|
||||
components
|
||||
}).$mount()
|
||||
|
||||
vm.view = 'two'
|
||||
waitForUpdate(() => {
|
||||
assertHookCalls(one, [1, 1, 1, 1, 0])
|
||||
assertHookCalls(two, [1, 1, 1, 0, 0])
|
||||
vm.include = 'one'
|
||||
vm.view = 'one'
|
||||
}).then(() => {
|
||||
assertHookCalls(one, [1, 1, 2, 1, 0])
|
||||
// two should be pruned
|
||||
assertHookCalls(two, [1, 1, 1, 1, 1])
|
||||
}).then(done)
|
||||
})
|
||||
|
||||
it('should not prune currently active instance', done => {
|
||||
const vm = new Vue({
|
||||
template: `
|
||||
|
Loading…
Reference in New Issue
Block a user