Nuxt/packages/app/template/components/nuxt.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-10-24 13:46:06 +00:00
<%= isTest ? '// @vue/component' : '' %>
import Vue from 'vue'
2018-10-24 13:46:06 +00:00
import { compile } from '../utils'
<% if (components.ErrorPage) { %>
<% if (('~@').includes(components.ErrorPage.charAt(0))) { %>
import NuxtError from '<%= components.ErrorPage %>'
<% } else { %>
import NuxtError from '<%= "../" + components.ErrorPage %>'
<% } %>
<% } else { %>
import NuxtError from './nuxt-error.vue'
<% } %>
2018-10-24 13:46:06 +00:00
import NuxtChild from './nuxt-child'
export default {
name: 'nuxt',
2018-10-24 13:46:06 +00:00
props: {
nuxtChildKey: String,
keepAlive: Boolean
},
2017-10-07 09:47:31 +00:00
render(h) {
// If there is some error
if (this.nuxt.err) {
return h('nuxt-error', {
props: {
error: this.nuxt.err
}
})
}
// Directly return nuxt child
return h('nuxt-child', {
key: this.routerViewKey,
props: this.$props
2017-10-07 09:47:31 +00:00
})
},
2018-10-24 13:46:06 +00:00
beforeCreate() {
Vue.util.defineReactive(this, 'nuxt', this.$root.$options.nuxt)
},
computed: {
2018-10-24 13:46:06 +00:00
routerViewKey() {
2017-07-09 14:29:14 +00:00
// If nuxtChildKey prop is given or current route has children
if (typeof this.nuxtChildKey !== 'undefined' || this.$route.matched.length > 1) {
return this.nuxtChildKey || compile(this.$route.matched[0].path)(this.$route.params)
}
const Component = this.$route.matched[0] && this.$route.matched[0].components.default
if (Component && Component.options && Component.options.key) {
return (typeof Component.options.key === 'function' ? Component.options.key(this.$route) : Component.options.key)
}
return this.$route.path
}
},
components: {
2016-12-16 16:45:47 +00:00
NuxtChild,
NuxtError
}
}