2016-11-19 21:16:26 +00:00
|
|
|
<template>
|
2017-02-09 23:47:35 +00:00
|
|
|
<nuxt-error v-if="nuxt.err" :error="nuxt.err"></nuxt-error>
|
|
|
|
<nuxt-child v-else></nuxt-child>
|
2016-11-19 21:16:26 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2016-11-21 13:14:35 +00:00
|
|
|
import Vue from 'vue'
|
2016-12-16 16:45:47 +00:00
|
|
|
import NuxtChild from './nuxt-child'
|
2017-06-29 16:36:22 +00:00
|
|
|
import NuxtError from '<%= components.ErrorPage ? ((components.ErrorPage.includes('~') || components.ErrorPage.includes('@')) ? components.ErrorPage : "../" + components.ErrorPage) : "./nuxt-error.vue" %>'
|
2016-11-19 21:16:26 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'nuxt',
|
2016-11-21 13:14:35 +00:00
|
|
|
beforeCreate () {
|
|
|
|
Vue.util.defineReactive(this, 'nuxt', this.$root.$options._nuxt)
|
2016-11-19 21:16:26 +00:00
|
|
|
},
|
|
|
|
created () {
|
2016-11-21 13:14:35 +00:00
|
|
|
// Add this.$nuxt in child instances
|
2016-11-19 21:16:26 +00:00
|
|
|
Vue.prototype.$nuxt = this
|
2016-11-21 13:14:35 +00:00
|
|
|
// Add this.$root.$nuxt
|
|
|
|
this.$root.$nuxt = this
|
2016-12-24 00:55:32 +00:00
|
|
|
// Bind $nuxt.setLayout(layout) to $root.setLayout
|
|
|
|
this.setLayout = this.$root.setLayout.bind(this.$root)
|
2016-11-19 21:16:26 +00:00
|
|
|
// add to window so we can listen when ready
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
window.$nuxt = this
|
|
|
|
}
|
2016-12-04 18:15:50 +00:00
|
|
|
// Add $nuxt.error()
|
|
|
|
this.error = this.$root.error
|
2016-11-19 21:16:26 +00:00
|
|
|
},
|
2016-11-21 13:14:35 +00:00
|
|
|
<% if (loading) { %>
|
2016-11-19 21:16:26 +00:00
|
|
|
mounted () {
|
2017-01-30 10:20:20 +00:00
|
|
|
if (this.$root.$loading && this.$root.$loading.start) {
|
|
|
|
this.$loading = this.$root.$loading
|
|
|
|
}
|
2016-11-19 21:16:26 +00:00
|
|
|
},
|
2016-11-21 13:14:35 +00:00
|
|
|
watch: {
|
|
|
|
'nuxt.err': 'errorChanged'
|
|
|
|
},
|
2016-11-19 21:16:26 +00:00
|
|
|
methods: {
|
2016-11-21 13:14:35 +00:00
|
|
|
errorChanged () {
|
|
|
|
if (this.nuxt.err && this.$loading) {
|
2016-11-19 21:16:26 +00:00
|
|
|
if (this.$loading.fail) this.$loading.fail()
|
|
|
|
if (this.$loading.finish) this.$loading.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-11-21 13:14:35 +00:00
|
|
|
<% } %>
|
2016-11-19 21:16:26 +00:00
|
|
|
components: {
|
2016-12-16 16:45:47 +00:00
|
|
|
NuxtChild,
|
2017-01-30 10:20:20 +00:00
|
|
|
NuxtError
|
2016-11-19 21:16:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|