Created
August 1, 2019 08:02
-
-
Save dobromir-hristov/de3f5dfdfc5158bfa7907f1c592cc9f7 to your computer and use it in GitHub Desktop.
Vuejs layout component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
/** | |
* Renderless component that loads a layout component and emits the appropriate event, for the App.vue to render it. | |
* @module Layout | |
* @see module:App to see how it is implemented. | |
* @see "/layouts" for all possible layouts to load | |
*/ | |
export default { | |
name: 'Layout', | |
props: { | |
name: { | |
type: String, | |
required: true | |
} | |
}, | |
created () { | |
// Check if the layout component | |
// has already been registered. | |
if (!Vue.options.components[this.name]) { | |
Vue.component( | |
this.name, | |
() => import(`@/router/layouts/${this.name}.vue`) | |
) | |
} | |
this.$parent.$emit('update:layout', this.name) | |
}, | |
render () { | |
return this.$slots.default[0] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment