Merge pull request #1310 from whtsky/resolve-vuecomponent

add `resolvedLayouts` to support class components in layouts
This commit is contained in:
Sébastien Chopin 2017-08-13 23:31:58 +02:00 committed by GitHub
commit 233ea26455

View File

@ -20,6 +20,8 @@ layoutsKeys.forEach(function (key, i) { %>
<% }) %> <% }) %>
} }
let resolvedLayouts = {}
export default { export default {
head: <%= JSON.stringify(head) %>, head: <%= JSON.stringify(head) %>,
data: () => ({ data: () => ({
@ -37,22 +39,23 @@ export default {
}, },
methods: { methods: {
setLayout (layout) { setLayout (layout) {
if (!layout || !layouts['_' + layout]) layout = 'default' if (!layout || !resolvedLayouts['_' + layout]) layout = 'default'
this.layoutName = layout this.layoutName = layout
let _layout = '_' + layout let _layout = '_' + layout
this.layout = layouts[_layout] this.layout = resolvedLayouts[_layout]
return this.layout return this.layout
}, },
loadLayout (layout) { loadLayout (layout) {
if (!layout || !layouts['_' + layout]) layout = 'default' if (!layout || !(layouts['_' + layout] || resolvedLayouts['_' + layout])) layout = 'default'
let _layout = '_' + layout let _layout = '_' + layout
if (typeof layouts[_layout] !== 'function') { if (resolvedLayouts[_layout]) {
return Promise.resolve(layouts[_layout]) return Promise.resolve(resolvedLayouts[_layout])
} }
return layouts[_layout]() return layouts[_layout]()
.then((Component) => { .then((Component) => {
layouts[_layout] = Component resolvedLayouts[_layout] = Component
return layouts[_layout] delete layouts[_layout]
return resolvedLayouts[_layout]
}) })
.catch((e) => { .catch((e) => {
if (this.$nuxt) { if (this.$nuxt) {