Move $nuxt into App

This commit is contained in:
Sébastien Chopin 2017-08-15 00:58:45 +02:00
parent 48b5ff3bfc
commit 7d370d8126
2 changed files with 24 additions and 36 deletions

View File

@ -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

View File

@ -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