From 4abbb4eb9cb6c46a1dc3ce632698dc5de6366b74 Mon Sep 17 00:00:00 2001 From: Wu Haotian Date: Mon, 7 Aug 2017 14:21:03 +0800 Subject: [PATCH 1/2] cache resolved layouts in resolvedLayouts --- lib/app/App.vue | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/app/App.vue b/lib/app/App.vue index d2e9f8a163..9febdf0078 100644 --- a/lib/app/App.vue +++ b/lib/app/App.vue @@ -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) { From e686844b036dfd50f77dd56641ecc9203e7eb3d6 Mon Sep 17 00:00:00 2001 From: Wu Haotian Date: Mon, 7 Aug 2017 15:11:47 +0800 Subject: [PATCH 2/2] App.vue: check `resolvedLayouts` in `setLayout` --- lib/app/App.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/app/App.vue b/lib/app/App.vue index 9febdf0078..aa5edcde53 100644 --- a/lib/app/App.vue +++ b/lib/app/App.vue @@ -35,14 +35,14 @@ export default { <% } %> methods: { setLayout (layout) { - if (!layout || !layouts['_' + layout]) layout = 'default' + if (!layout || !resolvedLayouts['_' + layout]) layout = 'default' this.layoutName = layout let _layout = '_' + layout - this.layout = layouts[_layout] + this.layout = resolvedLayouts[_layout] return this.layout }, loadLayout (layout) { - if (!layout || !layouts['_' + layout]) layout = 'default' + if (!layout || !(layouts['_' + layout] || resolvedLayouts['_' + layout])) layout = 'default' let _layout = '_' + layout if (resolvedLayouts[_layout]) { return Promise.resolve(resolvedLayouts[_layout])