cache resolved layouts in resolvedLayouts

This commit is contained in:
Wu Haotian 2017-08-07 14:21:03 +08:00
parent 1c527c2db6
commit 4abbb4eb9c
No known key found for this signature in database
GPG Key ID: 9A146A3AA793AACB

View File

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