mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
12e6b6cb9c
Since the rest of the file is using spaces, I changed the tabs before `NuxtLoading` to spaces as well.
54 lines
1.4 KiB
Vue
54 lines
1.4 KiB
Vue
<template>
|
|
<div>
|
|
<% if (loading) { %><nuxt-loading ref="loading"></nuxt-loading><% } %>
|
|
<transition :name="nuxt.transition.name" :mode="nuxt.transition.mode">
|
|
<router-view v-if="!nuxt.err"></router-view>
|
|
<nuxt-error v-if="nuxt.err" :error="nuxt.err"></nuxt-error>
|
|
</transition>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import Vue from 'vue'
|
|
import NuxtError from '<%= components.ErrorPage %>'
|
|
<% if (loading) { %>import NuxtLoading from '<%= (typeof loading === "string" ? loading : "./nuxt-loading.vue") %>'<% } %>
|
|
|
|
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
|
|
// 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 () {
|
|
this.$loading = this.$refs.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: {
|
|
NuxtError<%= (loading ? ',\n NuxtLoading' : '') %>
|
|
}
|
|
}
|
|
</script>
|