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

Commit6d6b373

Browse files
committed
fix: should warn unknown components inside <keep-alive>
1 parentf5cd29e commit6d6b373

File tree

2 files changed

+76
-68
lines changed

2 files changed

+76
-68
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export default {
8181
},
8282

8383
render(){
84-
constvnode:VNode=getFirstComponentChild(this.$slots.default)
84+
constslot=this.$slots.default
85+
constvnode:VNode=getFirstComponentChild(slot)
8586
constcomponentOptions: ?VNodeComponentOptions=vnode&&vnode.componentOptions
8687
if(componentOptions){
8788
// check pattern
@@ -115,6 +116,6 @@ export default {
115116

116117
vnode.data.keepAlive = true
117118
}
118-
returnvnode
119+
returnvnode||(slot&&slot[0])
119120
}
120121
}

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

Lines changed: 73 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,79 @@ describe('Component keep-alive', () => {
477477
}).then(done)
478478
})
479479

480+
it('max',done=>{
481+
constspyA=jasmine.createSpy()
482+
constspyB=jasmine.createSpy()
483+
constspyC=jasmine.createSpy()
484+
constspyAD=jasmine.createSpy()
485+
constspyBD=jasmine.createSpy()
486+
constspyCD=jasmine.createSpy()
487+
488+
functionassertCount(calls){
489+
expect([
490+
spyA.calls.count(),
491+
spyAD.calls.count(),
492+
spyB.calls.count(),
493+
spyBD.calls.count(),
494+
spyC.calls.count(),
495+
spyCD.calls.count()
496+
]).toEqual(calls)
497+
}
498+
499+
constvm=newVue({
500+
template:`
501+
<keep-alive max="2">
502+
<component :is="n"></component>
503+
</keep-alive>
504+
`,
505+
data:{
506+
n:'aa'
507+
},
508+
components:{
509+
aa:{
510+
template:'<div>a</div>',
511+
created:spyA,
512+
destroyed:spyAD
513+
},
514+
bb:{
515+
template:'<div>bbb</div>',
516+
created:spyB,
517+
destroyed:spyBD
518+
},
519+
cc:{
520+
template:'<div>ccc</div>',
521+
created:spyC,
522+
destroyed:spyCD
523+
}
524+
}
525+
}).$mount()
526+
527+
assertCount([1,0,0,0,0,0])
528+
vm.n='bb'
529+
waitForUpdate(()=>{
530+
assertCount([1,0,1,0,0,0])
531+
vm.n='cc'
532+
}).then(()=>{
533+
// should prune A because max cache reached
534+
assertCount([1,1,1,0,1,0])
535+
vm.n='bb'
536+
}).then(()=>{
537+
// B should be reused, and made latest
538+
assertCount([1,1,1,0,1,0])
539+
vm.n='aa'
540+
}).then(()=>{
541+
// C should be pruned because B was used last so C is the oldest cached
542+
assertCount([2,1,1,0,1,1])
543+
}).then(done)
544+
})
545+
546+
it('should warn unknown component inside',()=>{
547+
newVue({
548+
template:`<keep-alive><foo/></keep-alive>`
549+
}).$mount()
550+
expect(`Unknown custom element: <foo>`).toHaveBeenWarned()
551+
})
552+
480553
if(!isIE9){
481554
it('with transition-mode out-in',done=>{
482555
letnext
@@ -946,71 +1019,5 @@ describe('Component keep-alive', () => {
9461019
}).then(done)
9471020
}
9481021
})
949-
950-
it('max',done=>{
951-
constspyA=jasmine.createSpy()
952-
constspyB=jasmine.createSpy()
953-
constspyC=jasmine.createSpy()
954-
constspyAD=jasmine.createSpy()
955-
constspyBD=jasmine.createSpy()
956-
constspyCD=jasmine.createSpy()
957-
958-
functionassertCount(calls){
959-
expect([
960-
spyA.calls.count(),
961-
spyAD.calls.count(),
962-
spyB.calls.count(),
963-
spyBD.calls.count(),
964-
spyC.calls.count(),
965-
spyCD.calls.count()
966-
]).toEqual(calls)
967-
}
968-
969-
constvm=newVue({
970-
template:`
971-
<keep-alive max="2">
972-
<component :is="n"></component>
973-
</keep-alive>
974-
`,
975-
data:{
976-
n:'aa'
977-
},
978-
components:{
979-
aa:{
980-
template:'<div>a</div>',
981-
created:spyA,
982-
destroyed:spyAD
983-
},
984-
bb:{
985-
template:'<div>bbb</div>',
986-
created:spyB,
987-
destroyed:spyBD
988-
},
989-
cc:{
990-
template:'<div>ccc</div>',
991-
created:spyC,
992-
destroyed:spyCD
993-
}
994-
}
995-
}).$mount()
996-
997-
assertCount([1,0,0,0,0,0])
998-
vm.n='bb'
999-
waitForUpdate(()=>{
1000-
assertCount([1,0,1,0,0,0])
1001-
vm.n='cc'
1002-
}).then(()=>{
1003-
// should prune A because max cache reached
1004-
assertCount([1,1,1,0,1,0])
1005-
vm.n='bb'
1006-
}).then(()=>{
1007-
// B should be reused, and made latest
1008-
assertCount([1,1,1,0,1,0])
1009-
vm.n='aa'
1010-
}).then(()=>{
1011-
// C should be pruned because B was used last so C is the oldest cached
1012-
assertCount([2,1,1,0,1,1])
1013-
}).then(done)
1014-
})
10151022
}
10161023
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp