diff --git a/packages/@vuepress/core/lib/client/components/Content.js b/packages/@vuepress/core/lib/client/components/Content.js index b4811acf..5e8bad55 100644 --- a/packages/@vuepress/core/lib/client/components/Content.js +++ b/packages/@vuepress/core/lib/client/components/Content.js @@ -8,7 +8,7 @@ export default { }, render (h) { const pageKey = this.pageKey || this.$parent.$page.key - if (this.$vuepress.isPageExists(pageKey)) { + if (this.$hasComponent(pageKey)) { return h(pageKey) } return h('') diff --git a/packages/@vuepress/core/lib/client/components/GlobalLayout.vue b/packages/@vuepress/core/lib/client/components/GlobalLayout.vue index e137bb3c..bfcf5511 100644 --- a/packages/@vuepress/core/lib/client/components/GlobalLayout.vue +++ b/packages/@vuepress/core/lib/client/components/GlobalLayout.vue @@ -7,7 +7,7 @@ export default { computed: { layout () { if (this.$page.path) { - if (this.$vuepress.isLayoutExists(this.$page.frontmatter.layout)) { + if (this.$hasComponent(this.$page.frontmatter.layout)) { return this.$page.frontmatter.layout } return 'Layout' diff --git a/packages/@vuepress/core/lib/client/plugins/Store.d.ts b/packages/@vuepress/core/lib/client/plugins/Store.d.ts index d290e852..007d0b68 100644 --- a/packages/@vuepress/core/lib/client/plugins/Store.d.ts +++ b/packages/@vuepress/core/lib/client/plugins/Store.d.ts @@ -1,15 +1,13 @@ import Vue from 'Vue' export declare class Store { - store: Vue; + store: Vue - $get(key: string): any; + $get(key: string): any - $set(key: string, value: any): void; + $set(key: string, value: any): void - $emit: typeof Vue.prototype.$emit; + $emit: typeof Vue.prototype.$emit - $on: typeof Vue.prototype.$on; + $on: typeof Vue.prototype.$on } - - diff --git a/packages/@vuepress/core/lib/client/plugins/VuePress.d.ts b/packages/@vuepress/core/lib/client/plugins/VuePress.d.ts index 48af0be1..3d6eba73 100644 --- a/packages/@vuepress/core/lib/client/plugins/VuePress.d.ts +++ b/packages/@vuepress/core/lib/client/plugins/VuePress.d.ts @@ -1,14 +1,8 @@ -import { Store } from './Store'; -import { AsyncComponent } from 'vue' +import { Store } from './Store' -declare class VuePress extends Store { - isPageExists (pageKey: string): boolean; - - isLayoutExists (pageKey: string): boolean; -} - -declare module "vue/types/vue" { +declare module 'vue/types/vue' { export interface Vue { - $vuepress: VuePress; + $vuepress: Store + $hasComponent (key: string): boolean } } diff --git a/packages/@vuepress/core/lib/client/plugins/VuePress.js b/packages/@vuepress/core/lib/client/plugins/VuePress.js index c5043b31..afa90fa9 100644 --- a/packages/@vuepress/core/lib/client/plugins/VuePress.js +++ b/packages/@vuepress/core/lib/client/plugins/VuePress.js @@ -1,4 +1,3 @@ -import Vue from 'vue' import Store from './Store' // TODO: reuse this function in shared-utils @@ -14,20 +13,11 @@ function cached (fn) { const pascalize = cached((str = '') => str.replace(/(^|-)\w/g, s => s.slice(-1).toUpperCase())) -class VuePress extends Store { - isPageExists (pageKey) { - return Boolean(Vue.component(pascalize(pageKey))) - } - - isLayoutExists (layout) { - return Boolean(Vue.component(pascalize(layout))) - } -} - export default { install (Vue) { - const ins = new VuePress() - Vue.$vuepress = ins - Vue.prototype.$vuepress = ins + const vuepress = new Store() + Vue.$vuepress = vuepress + Vue.prototype.$vuepress = vuepress + Vue.prototype.$hasComponent = key => Boolean(Vue.component(pascalize(key))) } } diff --git a/packages/docs/docs/theme/option-api.md b/packages/docs/docs/theme/option-api.md index 57ac02cd..0f8d7b0a 100755 --- a/packages/docs/docs/theme/option-api.md +++ b/packages/docs/docs/theme/option-api.md @@ -111,7 +111,7 @@ export default { computed: { layout () { if (this.$page.path) { - if (this.$vuepress.isLayoutExists(this.$frontmatter.layout)) { + if (this.$hasComponent(this.$frontmatter.layout)) { return this.$frontmatter.layout } return 'Layout' diff --git a/packages/docs/docs/zh/theme/option-api.md b/packages/docs/docs/zh/theme/option-api.md index 3fb8ccd3..3a665eff 100755 --- a/packages/docs/docs/zh/theme/option-api.md +++ b/packages/docs/docs/zh/theme/option-api.md @@ -111,7 +111,7 @@ export default { computed: { layout () { if (this.$page.path) { - if (this.$vuepress.isLayoutExists(this.$frontmatter.layout)) { + if (this.$hasComponent(this.$frontmatter.layout)) { return this.$frontmatter.layout } return 'Layout'