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") %>'<% } %>
|
2018-08-15 13:23:03 +00:00
|
|
|
<% css.forEach((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
|
|
|
|
2018-08-06 00:12:44 +00:00
|
|
|
<%= Object.keys(layouts).map((key) => {
|
2018-03-19 18:40:33 +00:00
|
|
|
if (splitChunks.layouts) {
|
2018-05-02 09:55:18 +00:00
|
|
|
return `const _${hash(key)} = () => import('${layouts[key]}' /* webpackChunkName: "${wChunk('layouts/' + key)}" */).then(m => m.default || m)`
|
2018-03-13 14:36:49 +00:00
|
|
|
} else {
|
2018-03-13 16:41:20 +00:00
|
|
|
return `import _${hash(key)} from '${layouts[key]}'`
|
2018-03-13 14:36:49 +00:00
|
|
|
}
|
|
|
|
}).join('\n') %>
|
2016-12-24 00:55:32 +00:00
|
|
|
|
2018-10-24 13:46:06 +00:00
|
|
|
const layouts = { <%= Object.keys(layouts).map(key => `"_${key}": _${hash(key)}`).join(',') %> }<%= isTest ? '// eslint-disable-line' : '' %>
|
2018-03-13 14:36:49 +00:00
|
|
|
|
2018-03-19 18:40:33 +00:00
|
|
|
<% if (splitChunks.layouts) { %>let resolvedLayouts = {}<% } %>
|
2017-08-07 06:21:03 +00:00
|
|
|
|
2016-12-24 00:55:32 +00:00
|
|
|
export default {
|
2018-10-24 13:46:06 +00:00
|
|
|
<%= isTest ? '/* eslint-disable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, object-property-newline, arrow-parens */' : '' %>
|
2018-11-07 22:33:09 +00:00
|
|
|
head: <%= serialize(head).replace(/:\w+\(/gm, ':function(').replace('head(', 'function(') %>,
|
2018-10-24 13:46:06 +00:00
|
|
|
<%= isTest ? '/* eslint-enable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, object-property-newline, arrow-parens */' : '' %>
|
2017-10-07 09:43:09 +00:00
|
|
|
render(h, props) {
|
|
|
|
<% if (loading) { %>const loadingEl = h('nuxt-loading', { ref: 'loading' })<% } %>
|
2017-11-06 17:30:15 +00:00
|
|
|
const layoutEl = h(this.layout || 'nuxt')
|
|
|
|
const templateEl = h('div', {
|
|
|
|
domProps: {
|
|
|
|
id: '__layout'
|
|
|
|
},
|
2017-10-07 09:43:09 +00:00
|
|
|
key: this.layoutName
|
2017-11-06 17:30:15 +00:00
|
|
|
}, [ layoutEl ])
|
2017-10-07 09:43:09 +00:00
|
|
|
|
|
|
|
const transitionEl = h('transition', {
|
|
|
|
props: {
|
|
|
|
name: '<%= layoutTransition.name %>',
|
|
|
|
mode: '<%= layoutTransition.mode %>'
|
|
|
|
}
|
2017-11-06 17:30:15 +00:00
|
|
|
}, [ templateEl ])
|
2017-10-07 09:43:09 +00:00
|
|
|
|
2018-10-24 13:46:06 +00:00
|
|
|
return h('div', {
|
2017-10-07 09:49:30 +00:00
|
|
|
domProps: {
|
2018-10-09 12:07:23 +00:00
|
|
|
id: '<%= globals.id %>'
|
2017-10-07 09:49:30 +00:00
|
|
|
}
|
|
|
|
}, [
|
2017-10-07 09:43:09 +00:00
|
|
|
<% if (loading) { %>loadingEl,<% } %>
|
|
|
|
transitionEl
|
|
|
|
])
|
|
|
|
},
|
2016-12-24 13:15:00 +00:00
|
|
|
data: () => ({
|
|
|
|
layout: null,
|
|
|
|
layoutName: ''
|
|
|
|
}),
|
2018-10-24 13:46:06 +00:00
|
|
|
beforeCreate() {
|
2017-10-13 21:53:04 +00:00
|
|
|
Vue.util.defineReactive(this, 'nuxt', this.$options.nuxt)
|
2017-08-14 22:58:45 +00:00
|
|
|
},
|
2018-10-24 13:46:06 +00:00
|
|
|
created() {
|
2017-08-14 22:58:45 +00:00
|
|
|
// Add this.$nuxt in child instances
|
2018-10-09 12:07:23 +00:00
|
|
|
Vue.prototype.<%= globals.nuxt %> = this
|
2017-08-14 22:58:45 +00:00
|
|
|
// add to window so we can listen when ready
|
|
|
|
if (typeof window !== 'undefined') {
|
2018-10-09 12:07:23 +00:00
|
|
|
window.<%= globals.nuxt %> = this
|
|
|
|
<% if (globals.nuxt !== '$nuxt') { %>
|
2018-11-11 11:22:50 +00:00
|
|
|
window.$nuxt = { $root: { constructor: this.$root.constructor } }
|
2018-10-09 12:07:23 +00:00
|
|
|
<% } %>
|
2017-08-14 22:58:45 +00:00
|
|
|
}
|
|
|
|
// Add $nuxt.error()
|
|
|
|
this.error = this.nuxt.error
|
|
|
|
},
|
2017-01-30 10:20:20 +00:00
|
|
|
<% if (loading) { %>
|
2018-10-24 13:46:06 +00:00
|
|
|
mounted() {
|
2017-01-30 10:20:20 +00:00
|
|
|
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) { %>
|
2018-10-24 13:46:06 +00:00
|
|
|
errorChanged() {
|
2017-08-14 22:58:45 +00:00
|
|
|
if (this.nuxt.err && this.$loading) {
|
|
|
|
if (this.$loading.fail) this.$loading.fail()
|
|
|
|
if (this.$loading.finish) this.$loading.finish()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
<% } %>
|
2018-03-19 18:40:33 +00:00
|
|
|
<% if (splitChunks.layouts) { %>
|
2018-10-24 13:46:06 +00:00
|
|
|
setLayout(layout) {
|
2018-10-20 19:47:47 +00:00
|
|
|
<% if (debug) { %>
|
|
|
|
if(layout && typeof layout !== 'string') throw new Error('[nuxt] Avoid using non-string value as layout property.')
|
|
|
|
<% } %>
|
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
|
|
|
},
|
2018-10-24 13:46:06 +00:00
|
|
|
loadLayout(layout) {
|
2018-08-06 00:12:44 +00:00
|
|
|
const undef = !layout
|
2018-08-17 08:22:52 +00:00
|
|
|
const inexisting = !(layouts['_' + layout] || resolvedLayouts['_' + layout])
|
|
|
|
let _layout = '_' + ((undef || inexisting) ? 'default' : 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]()
|
2018-03-13 14:36:49 +00:00
|
|
|
.then((Component) => {
|
|
|
|
resolvedLayouts[_layout] = Component
|
|
|
|
delete layouts[_layout]
|
|
|
|
return resolvedLayouts[_layout]
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
2018-10-09 12:07:23 +00:00
|
|
|
if (this.<%= globals.nuxt %>) {
|
|
|
|
return this.<%= globals.nuxt %>.error({ statusCode: 500, message: e.message })
|
2018-03-13 14:36:49 +00:00
|
|
|
}
|
|
|
|
})
|
2016-12-24 00:55:32 +00:00
|
|
|
}
|
2018-03-13 14:36:49 +00:00
|
|
|
<% } else { %>
|
|
|
|
setLayout(layout) {
|
2018-10-20 19:47:47 +00:00
|
|
|
<% if (debug) { %>
|
|
|
|
if(layout && typeof layout !== 'string') throw new Error('[nuxt] Avoid using non-string value as layout property.')
|
|
|
|
<% } %>
|
2018-08-06 00:12:44 +00:00
|
|
|
if (!layout || !layouts['_' + layout]) {
|
|
|
|
layout = 'default'
|
|
|
|
}
|
2018-03-13 14:36:49 +00:00
|
|
|
this.layoutName = layout
|
|
|
|
this.layout = layouts['_' + layout]
|
|
|
|
return this.layout
|
|
|
|
},
|
|
|
|
loadLayout(layout) {
|
2018-08-06 00:12:44 +00:00
|
|
|
if (!layout || !layouts['_' + layout]) {
|
|
|
|
layout = 'default'
|
|
|
|
}
|
2018-03-13 14:36:49 +00:00
|
|
|
return Promise.resolve(layouts['_' + layout])
|
|
|
|
}
|
|
|
|
<% } %>
|
2017-01-30 10:20:20 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
<%= (loading ? 'NuxtLoading' : '') %>
|
2016-12-24 00:55:32 +00:00
|
|
|
}
|
|
|
|
}
|