From 47e9654e4fee5ba4beff4660b5c83c038f19e5f7 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Wed, 7 Nov 2018 02:18:09 +0800 Subject: [PATCH] fix: missing edit links under non-contentLoading situations --- .../@vuepress/core/lib/app/components/Content.vue | 9 +++------ packages/@vuepress/core/lib/app/plugins/VuePress.js | 6 +++--- .../core/lib/app/root-mixins/updateLoadingState.js | 13 +++++++++++++ .../core/lib/internal-plugins/rootMixins.js | 3 ++- .../@vuepress/plugin-active-header-links/mixin.js | 1 - 5 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js diff --git a/packages/@vuepress/core/lib/app/components/Content.vue b/packages/@vuepress/core/lib/app/components/Content.vue index 3f2ea5443d..98b8428787 100644 --- a/packages/@vuepress/core/lib/app/components/Content.vue +++ b/packages/@vuepress/core/lib/app/components/Content.vue @@ -35,7 +35,7 @@ export default { }, computed: { - $key () { + $pageKey () { return this.pageKey || this.$page.key }, disableTransition () { @@ -44,14 +44,11 @@ export default { }, created () { - this.loadContent(this.$key) - this.$vuepress.$on('AsyncMarkdownContentMounted', (slotKey) => { - this.$vuepress.$set('contentMounted', true) - }) + this.loadContent(this.$pageKey) }, watch: { - $key (key) { + $pageKey (key) { this.$vuepress.$set('contentMounted', false) this.reloadContent(key) } diff --git a/packages/@vuepress/core/lib/app/plugins/VuePress.js b/packages/@vuepress/core/lib/app/plugins/VuePress.js index 76d4c39c3f..d907455c51 100644 --- a/packages/@vuepress/core/lib/app/plugins/VuePress.js +++ b/packages/@vuepress/core/lib/app/plugins/VuePress.js @@ -29,8 +29,8 @@ class VuePress extends Store { export default { install (Vue) { - const store = new VuePress() - Vue.$vuepress = store - Vue.prototype.$vuepress = store + const ins = new VuePress() + Vue.$vuepress = ins + Vue.prototype.$vuepress = ins } } diff --git a/packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js b/packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js new file mode 100644 index 0000000000..4711e8d4da --- /dev/null +++ b/packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js @@ -0,0 +1,13 @@ +export default { + created () { + this.$vuepress.$on('AsyncMarkdownContentMounted', () => { + this.$vuepress.$set('contentMounted', true) + }) + }, + + watch: { + $page () { + this.$vuepress.$set('contentMounted', false) + } + } +} diff --git a/packages/@vuepress/core/lib/internal-plugins/rootMixins.js b/packages/@vuepress/core/lib/internal-plugins/rootMixins.js index 929f29f092..f081bc7b84 100644 --- a/packages/@vuepress/core/lib/internal-plugins/rootMixins.js +++ b/packages/@vuepress/core/lib/internal-plugins/rootMixins.js @@ -7,7 +7,8 @@ module.exports = (options, context, api) => ({ // @internal/root-mixins async clientDynamicModules () { const builtInRootMixins = [ - path.resolve(__dirname, '../app/root-mixins/updateMeta.js') + path.resolve(__dirname, '../app/root-mixins/updateMeta.js'), + path.resolve(__dirname, '../app/root-mixins/updateLoadingState.js') ] const rootMixins = [ diff --git a/packages/@vuepress/plugin-active-header-links/mixin.js b/packages/@vuepress/plugin-active-header-links/mixin.js index 1d25143025..9868496985 100644 --- a/packages/@vuepress/plugin-active-header-links/mixin.js +++ b/packages/@vuepress/plugin-active-header-links/mixin.js @@ -44,7 +44,6 @@ function getAnchors () { export default { mounted () { this.$vuepress.$on('AsyncMarkdownContentMounted', (slotKey) => { - console.warn('AsyncMarkdownContentMounted') if (slotKey === 'default') { window.addEventListener('scroll', this.onScroll) }