mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-27 13:52:38 +00:00
cache resolved layouts in resolvedLayouts
This commit is contained in:
parent
1c527c2db6
commit
4abbb4eb9c
@ -19,6 +19,8 @@ layoutsKeys.forEach(function (key, i) { %>
|
|||||||
<% }) %>
|
<% }) %>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let resolvedLayouts = {}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
head: <%= JSON.stringify(head) %>,
|
head: <%= JSON.stringify(head) %>,
|
||||||
data: () => ({
|
data: () => ({
|
||||||
@ -42,13 +44,14 @@ export default {
|
|||||||
loadLayout (layout) {
|
loadLayout (layout) {
|
||||||
if (!layout || !layouts['_' + layout]) layout = 'default'
|
if (!layout || !layouts['_' + 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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user