Skip to content

Instantly share code, notes, and snippets.

@dobromir-hristov
Created August 1, 2019 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dobromir-hristov/de3f5dfdfc5158bfa7907f1c592cc9f7 to your computer and use it in GitHub Desktop.
Save dobromir-hristov/de3f5dfdfc5158bfa7907f1c592cc9f7 to your computer and use it in GitHub Desktop.
Vuejs layout component
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