From 7d370d8126a7db6a733c2ff233c29a543aed75f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Tue, 15 Aug 2017 00:58:45 +0200 Subject: [PATCH] Move $nuxt into App --- lib/app/App.vue | 28 ++++++++++++++++++++++++---- lib/app/components/nuxt.vue | 32 -------------------------------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/lib/app/App.vue b/lib/app/App.vue index 5592b88f2a..13233fcdcf 100644 --- a/lib/app/App.vue +++ b/lib/app/App.vue @@ -28,16 +28,36 @@ export default { layout: null, layoutName: '' }), + beforeCreate () { + Vue.util.defineReactive(this, 'nuxt', this.$options._nuxt) + }, + created () { + // Add this.$nuxt in child instances + Vue.prototype.$nuxt = this + // add to window so we can listen when ready + if (typeof window !== 'undefined') { + window.$nuxt = this + } + // Add $nuxt.error() + this.error = this.nuxt.error + }, <% if (loading) { %> mounted () { this.$loading = this.$refs.loading - this.$nuxt.$loading = this.$loading + }, + watch: { + 'nuxt.err': 'errorChanged' }, <% } %> - beforeCreate () { - Vue.util.defineReactive(this, 'nuxt', this.$root.$options._nuxt) - }, methods: { + <% if (loading) { %> + errorChanged () { + if (this.nuxt.err && this.$loading) { + if (this.$loading.fail) this.$loading.fail() + if (this.$loading.finish) this.$loading.finish() + } + }, + <% } %> setLayout (layout) { if (!layout || !resolvedLayouts['_' + layout]) layout = 'default' this.layoutName = layout diff --git a/lib/app/components/nuxt.vue b/lib/app/components/nuxt.vue index 96a67ce612..2817b3af9a 100644 --- a/lib/app/components/nuxt.vue +++ b/lib/app/components/nuxt.vue @@ -15,38 +15,6 @@ export default { beforeCreate () { Vue.util.defineReactive(this, 'nuxt', this.$root.$options._nuxt) }, - created () { - // Add this.$nuxt in child instances - Vue.prototype.$nuxt = this - // Add this.$root.$nuxt - this.$root.$nuxt = this - // Bind $nuxt.setLayout(layout) to $root.setLayout - this.setLayout = this.$root.setLayout.bind(this.$root) - // add to window so we can listen when ready - if (typeof window !== 'undefined') { - window.$nuxt = this - } - // Add $nuxt.error() - this.error = this.$root.error - }, - <% if (loading) { %> - mounted () { - if (this.$root.$loading && this.$root.$loading.start) { - this.$loading = this.$root.$loading - } - }, - watch: { - 'nuxt.err': 'errorChanged' - }, - methods: { - errorChanged () { - if (this.nuxt.err && this.$loading) { - if (this.$loading.fail) this.$loading.fail() - if (this.$loading.finish) this.$loading.finish() - } - } - }, - <% } %> computed: { routerViewKey () { // If nuxtChildKey prop is given or current route has children