rewrite nuxt.vue with render function

This commit is contained in:
Pooya Parsa 2017-10-07 13:17:31 +03:30
parent 870cbd6278
commit e4af41f529

View File

@ -1,10 +1,3 @@
<template>
<div class="nuxt">
<nuxt-error v-if="nuxt.err" :error="nuxt.err"></nuxt-error>
<nuxt-child :key="routerViewKey" v-else></nuxt-child>
</div>
</template>
<script> <script>
import Vue from 'vue' import Vue from 'vue'
import NuxtChild from './nuxt-child' import NuxtChild from './nuxt-child'
@ -14,6 +7,20 @@ import { compile } from '../utils'
export default { export default {
name: 'nuxt', name: 'nuxt',
props: ['nuxtChildKey'], props: ['nuxtChildKey'],
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
})
},
beforeCreate () { beforeCreate () {
Vue.util.defineReactive(this, 'nuxt', this.$root.$options._nuxt) Vue.util.defineReactive(this, 'nuxt', this.$root.$options._nuxt)
}, },