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

Commit4d8226f

Browse files
committed
fix: keep-alive should not cache anonymous components
This only happens if the component is returned by a intermediatefunctional or abstract component, e.g. <router-view>.Fixvuejs#6938.
1 parent6d6b373 commit4d8226f

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default {
8787
if(componentOptions){
8888
// check pattern
8989
constname: ?string=getComponentName(componentOptions)
90-
if(name&&(
90+
if(!name||(
9191
(this.exclude&&matches(this.exclude,name))||
9292
(this.include&&!matches(this.include,name))
9393
)){

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,60 @@ describe('Component keep-alive', () => {
550550
expect(`Unknown custom element: <foo>`).toHaveBeenWarned()
551551
})
552552

553+
// #6938
554+
it('should not cache anonymous component',done=>{
555+
constFoo={
556+
name:'foo',
557+
template:`<div>foo</div>`,
558+
created:jasmine.createSpy('foo')
559+
}
560+
561+
constBar={
562+
template:`<div>bar</div>`,
563+
created:jasmine.createSpy('bar')
564+
}
565+
566+
constChild={
567+
functional:true,
568+
render(h,ctx){
569+
returnh(ctx.props.view ?Foo :Bar)
570+
}
571+
}
572+
573+
constvm=newVue({
574+
template:`
575+
<keep-alive include="foo">
576+
<child :view="view"></child>
577+
</keep-alive>
578+
`,
579+
data:{
580+
view:true
581+
},
582+
components:{ Child}
583+
}).$mount()
584+
585+
functionassert(foo,bar){
586+
expect(Foo.created.calls.count()).toBe(foo)
587+
expect(Bar.created.calls.count()).toBe(bar)
588+
}
589+
590+
expect(vm.$el.textContent).toBe('foo')
591+
assert(1,0)
592+
vm.view=false
593+
waitForUpdate(()=>{
594+
expect(vm.$el.textContent).toBe('bar')
595+
assert(1,1)
596+
vm.view=true
597+
}).then(()=>{
598+
expect(vm.$el.textContent).toBe('foo')
599+
assert(1,1)
600+
vm.view=false
601+
}).then(()=>{
602+
expect(vm.$el.textContent).toBe('bar')
603+
assert(1,2)
604+
}).then(done)
605+
})
606+
553607
if(!isIE9){
554608
it('with transition-mode out-in',done=>{
555609
letnext

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp