Nuxt/lib/app/App.vue

54 lines
1.4 KiB
Vue
Raw Normal View History

2016-11-07 01:34:58 +00:00
<template>
2016-12-24 16:58:52 +00:00
<div id="__nuxt">
2016-12-24 11:34:41 +00:00
<component v-if="layout" :is="layout"></component>
2016-12-24 16:58:52 +00:00
</div>
2016-11-07 01:34:58 +00:00
</template>
2016-12-24 00:55:32 +00:00
<script>
let layouts = {
<%
var layoutsKeys = Object.keys(layouts);
layoutsKeys.forEach(function (key, i) { %>
"_<%= key %>": process.BROWSER_BUILD ? () => System.import('<%= layouts[key] %>') : require('<%= layouts[key] %>')<%= (i + 1) < layoutsKeys.length ? ',' : '' %>
2016-12-24 00:55:32 +00:00
<% }) %>
}
export default {
2016-12-24 16:58:52 +00:00
head: <%= JSON.stringify(head) %>,
2016-12-24 13:15:00 +00:00
data: () => ({
layout: null,
layoutName: ''
}),
2016-12-24 00:55:32 +00:00
methods: {
setLayout (layout) {
if (!layout || !layouts['_' + 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
if (typeof layouts[_layout] === 'function') {
return this.loadLayout(_layout)
}
this.layout = layouts[_layout]
return Promise.resolve(this.layout)
},
loadLayout (_layout) {
return layouts[_layout]()
.then((Component) => {
layouts[_layout] = Component
this.layout = layouts[_layout]
return this.layout
})
.catch((e) => {
if (this.$nuxt) {
return this.$nuxt.error({ statusCode: 500, message: e.message })
}
console.error(e)
})
2016-12-24 00:55:32 +00:00
}
}
}
</script>
2016-12-24 16:58:52 +00:00
<% css.forEach(function (c) { %>
<style src="<%= (typeof c === 'string' ? c : c.src) %>" lang="<%= (c.lang ? c.lang : 'css') %>"></style>
<% }) %>