Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commita23b913

Browse files
committed
fix: fix <keep-alive> include/exclude logic for anonymous components
1 parentb278120 commita23b913

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

‎src/core/components/keep-alive.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ export default {
8787
if(componentOptions){
8888
// check pattern
8989
constname: ?string=getComponentName(componentOptions)
90-
if(!name||(
91-
(this.exclude&&matches(this.exclude,name))||
92-
(this.include&&!matches(this.include,name))
93-
)){
90+
const{include, exclude}=this
91+
if(
92+
// not included
93+
(include&&(!name||!matches(include,name)))||
94+
// excluded
95+
(exclude&&name&&matches(exclude,name))
96+
){
9497
returnvnode
9598
}
9699

‎test/unit/features/component/component-keep-alive.spec.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ describe('Component keep-alive', () => {
551551
})
552552

553553
// #6938
554-
it('should not cache anonymous component',done=>{
554+
it('should not cache anonymous component when include is specified',done=>{
555555
constFoo={
556556
name:'foo',
557557
template:`<div>foo</div>`,
@@ -604,6 +604,58 @@ describe('Component keep-alive', () => {
604604
}).then(done)
605605
})
606606

607+
it('should cache anonymous components if include is not specified',done=>{
608+
constFoo={
609+
template:`<div>foo</div>`,
610+
created:jasmine.createSpy('foo')
611+
}
612+
613+
constBar={
614+
template:`<div>bar</div>`,
615+
created:jasmine.createSpy('bar')
616+
}
617+
618+
constChild={
619+
functional:true,
620+
render(h,ctx){
621+
returnh(ctx.props.view ?Foo :Bar)
622+
}
623+
}
624+
625+
constvm=newVue({
626+
template:`
627+
<keep-alive>
628+
<child :view="view"></child>
629+
</keep-alive>
630+
`,
631+
data:{
632+
view:true
633+
},
634+
components:{ Child}
635+
}).$mount()
636+
637+
functionassert(foo,bar){
638+
expect(Foo.created.calls.count()).toBe(foo)
639+
expect(Bar.created.calls.count()).toBe(bar)
640+
}
641+
642+
expect(vm.$el.textContent).toBe('foo')
643+
assert(1,0)
644+
vm.view=false
645+
waitForUpdate(()=>{
646+
expect(vm.$el.textContent).toBe('bar')
647+
assert(1,1)
648+
vm.view=true
649+
}).then(()=>{
650+
expect(vm.$el.textContent).toBe('foo')
651+
assert(1,1)
652+
vm.view=false
653+
}).then(()=>{
654+
expect(vm.$el.textContent).toBe('bar')
655+
assert(1,1)
656+
}).then(done)
657+
})
658+
607659
if(!isIE9){
608660
it('with transition-mode out-in',done=>{
609661
letnext

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp