fix(keep-alive): run prune after render for correct active component check

fix #7566
This commit is contained in:
Evan You 2018-03-12 13:05:31 -04:00
parent 4378fc5124
commit 215f877d1b
2 changed files with 34 additions and 5 deletions

View File

@ -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 () {

View File

@ -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: `