Nuxt/lib/app/components/nuxt.vue

54 lines
1.3 KiB
Vue
Raw Normal View History

<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>
</template>
<script>
import Vue from 'vue'
2016-12-16 16:45:47 +00:00
import NuxtChild from './nuxt-child'
import NuxtError from '<%= components.ErrorPage %>'
export default {
name: 'nuxt',
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
2016-12-24 00:55:32 +00:00
// 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
}
2016-12-04 18:15:50 +00:00
// 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()
}
}
},
<% } %>
components: {
2016-12-16 16:45:47 +00:00
NuxtChild,
NuxtError
}
}
</script>