2016-12-24 00:55:32 +00:00
|
|
|
<script>
|
2017-08-10 10:37:23 +00:00
|
|
|
import Vue from 'vue'
|
2017-01-30 10:20:20 +00:00
|
|
|
<% if (loading) { %>import NuxtLoading from '<%= (typeof loading === "string" ? loading : "./components/nuxt-loading.vue") %>'<% } %>
|
2017-05-05 14:10:12 +00:00
|
|
|
<% css.forEach(function (c) { %>
|
2017-07-21 23:40:38 +00:00
|
|
|
import '<%= relativeToBuild(resolvePath(c.src || c)) %>'
|
2017-05-05 14:10:12 +00:00
|
|
|
<% }) %>
|
2017-01-30 10:20:20 +00:00
|
|
|
|
2016-12-24 00:55:32 +00:00
|
|
|
let layouts = {
|
|
|
|
<%
|
|
|
|
var layoutsKeys = Object.keys(layouts);
|
|
|
|
layoutsKeys.forEach(function (key, i) { %>
|
2017-08-17 17:18:56 +00:00
|
|
|
"_<%= key %>": () => import('<%= layouts[key] %>' /* webpackChunkName: "<%= wChunk('layouts/'+key) %>" */).then(m => m.default || m)<%= (i + 1) < layoutsKeys.length ? ',' : '' %>
|
2016-12-24 00:55:32 +00:00
|
|
|
<% }) %>
|
|
|
|
}
|
|
|
|
|
2017-08-07 06:21:03 +00:00
|
|
|
let resolvedLayouts = {}
|
|
|
|
|
2016-12-24 00:55:32 +00:00
|
|
|
export default {
|
2016-12-24 16:58:52 +00:00
|
|
|
head: <%= JSON.stringify(head) %>,
|
2017-10-07 09:43:09 +00:00
|
|
|
render(h, props) {
|
|
|
|
<% if (loading) { %>const loadingEl = h('nuxt-loading', { ref: 'loading' })<% } %>
|
|
|
|
|
|
|
|
const layoutEl = h(this.nuxt.err ? 'nuxt' : this.layout, {
|
|
|
|
key: this.layoutName
|
|
|
|
})
|
|
|
|
|
|
|
|
const transitionEl = h('transition', {
|
|
|
|
props: {
|
|
|
|
name: '<%= layoutTransition.name %>',
|
|
|
|
mode: '<%= layoutTransition.mode %>'
|
|
|
|
}
|
|
|
|
}, [ layoutEl ])
|
|
|
|
|
2017-10-07 09:49:30 +00:00
|
|
|
return h('div',{
|
|
|
|
domProps: {
|
|
|
|
id: '__nuxt'
|
|
|
|
}
|
|
|
|
}, [
|
2017-10-07 09:43:09 +00:00
|
|
|
<% if (loading) { %>loadingEl,<% } %>
|
|
|
|
transitionEl
|
|
|
|
])
|
|
|
|
},
|
2016-12-24 13:15:00 +00:00
|
|
|
data: () => ({
|
|
|
|
layout: null,
|
|
|
|
layoutName: ''
|
|
|
|
}),
|
2017-08-14 22:58:45 +00:00
|
|
|
beforeCreate () {
|
|
|
|
Vue.util.defineReactive(this, 'nuxt', this.$options._nuxt)
|
|
|
|
},
|
|
|
|
created () {
|
|
|
|
// Add this.$nuxt in child instances
|
|
|
|
Vue.prototype.$nuxt = this
|
|
|
|
// add to window so we can listen when ready
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
window.$nuxt = this
|
|
|
|
}
|
|
|
|
// Add $nuxt.error()
|
|
|
|
this.error = this.nuxt.error
|
|
|
|
},
|
2017-01-30 10:20:20 +00:00
|
|
|
<% if (loading) { %>
|
|
|
|
mounted () {
|
|
|
|
this.$loading = this.$refs.loading
|
|
|
|
},
|
2017-08-14 22:58:45 +00:00
|
|
|
watch: {
|
|
|
|
'nuxt.err': 'errorChanged'
|
2017-08-10 10:37:23 +00:00
|
|
|
},
|
2017-08-14 22:58:45 +00:00
|
|
|
<% } %>
|
2016-12-24 00:55:32 +00:00
|
|
|
methods: {
|
2017-08-14 22:58:45 +00:00
|
|
|
<% if (loading) { %>
|
|
|
|
errorChanged () {
|
|
|
|
if (this.nuxt.err && this.$loading) {
|
|
|
|
if (this.$loading.fail) this.$loading.fail()
|
|
|
|
if (this.$loading.finish) this.$loading.finish()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
<% } %>
|
2016-12-24 00:55:32 +00:00
|
|
|
setLayout (layout) {
|
2017-08-07 07:11:47 +00:00
|
|
|
if (!layout || !resolvedLayouts['_' + layout]) layout = 'default'
|
2016-12-24 13:15:00 +00:00
|
|
|
this.layoutName = layout
|
2016-12-24 11:34:41 +00:00
|
|
|
let _layout = '_' + layout
|
2017-08-07 07:11:47 +00:00
|
|
|
this.layout = resolvedLayouts[_layout]
|
2017-02-20 22:11:34 +00:00
|
|
|
return this.layout
|
2016-12-24 11:34:41 +00:00
|
|
|
},
|
2017-02-20 22:11:34 +00:00
|
|
|
loadLayout (layout) {
|
2017-08-07 07:11:47 +00:00
|
|
|
if (!layout || !(layouts['_' + layout] || resolvedLayouts['_' + layout])) layout = 'default'
|
2017-02-20 22:11:34 +00:00
|
|
|
let _layout = '_' + layout
|
2017-08-07 06:21:03 +00:00
|
|
|
if (resolvedLayouts[_layout]) {
|
|
|
|
return Promise.resolve(resolvedLayouts[_layout])
|
2017-02-20 22:11:34 +00:00
|
|
|
}
|
2016-12-24 11:34:41 +00:00
|
|
|
return layouts[_layout]()
|
|
|
|
.then((Component) => {
|
2017-08-07 06:21:03 +00:00
|
|
|
resolvedLayouts[_layout] = Component
|
|
|
|
delete layouts[_layout]
|
|
|
|
return resolvedLayouts[_layout]
|
2016-12-24 11:34:41 +00:00
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
if (this.$nuxt) {
|
|
|
|
return this.$nuxt.error({ statusCode: 500, message: e.message })
|
|
|
|
}
|
|
|
|
})
|
2016-12-24 00:55:32 +00:00
|
|
|
}
|
2017-01-30 10:20:20 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
<%= (loading ? 'NuxtLoading' : '') %>
|
2016-12-24 00:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2016-12-24 16:58:52 +00:00
|
|
|
|