diff --git a/src/core/components/keep-alive.js b/src/core/components/keep-alive.js index 5573feed7d1..734570ca945 100644 --- a/src/core/components/keep-alive.js +++ b/src/core/components/keep-alive.js @@ -5,14 +5,16 @@ import { getFirstComponentChild } from 'core/vdom/helpers/index' type VNodeCache = { [key: string]: ?VNode }; -const patternTypes: Array = [String, RegExp] +const patternTypes: Array = [String, RegExp, Array] function getComponentName (opts: ?VNodeComponentOptions): ?string { return opts && (opts.Ctor.options.name || opts.tag) } -function matches (pattern: string | RegExp, name: string): boolean { - if (typeof pattern === 'string') { +function matches (pattern: string | RegExp | Array, name: string): boolean { + if (Array.isArray(pattern)) { + return pattern.indexOf(name) > -1 + } else if (typeof pattern === 'string') { return pattern.split(',').indexOf(name) > -1 } else if (isRegExp(pattern)) { return pattern.test(name) @@ -62,10 +64,10 @@ export default { }, watch: { - include (val: string | RegExp) { + include (val: string | RegExp | Array) { pruneCache(this.cache, this._vnode, name => matches(val, name)) }, - exclude (val: string | RegExp) { + exclude (val: string | RegExp | Array) { pruneCache(this.cache, this._vnode, name => !matches(val, name)) } }, diff --git a/test/unit/features/component/component-keep-alive.spec.js b/test/unit/features/component/component-keep-alive.spec.js index 7cc9f395772..1295c17f50e 100644 --- a/test/unit/features/component/component-keep-alive.spec.js +++ b/test/unit/features/component/component-keep-alive.spec.js @@ -272,6 +272,24 @@ describe('Component keep-alive', () => { sharedAssertions(vm, done) }) + it('include (array)', done => { + const vm = new Vue({ + template: ` +
+ + + +
+ `, + data: { + view: 'one', + ok: true + }, + components + }).$mount() + sharedAssertions(vm, done) + }) + it('exclude (string)', done => { const vm = new Vue({ template: ` @@ -308,6 +326,24 @@ describe('Component keep-alive', () => { sharedAssertions(vm, done) }) + it('exclude (array)', done => { + const vm = new Vue({ + template: ` +
+ + + +
+ `, + data: { + view: 'one', + ok: true + }, + components + }).$mount() + sharedAssertions(vm, done) + }) + it('include + exclude', done => { const vm = new Vue({ template: `