nixin-web/components/DynamicComponent.vue

34 lines
1,008 B
Vue
Raw Permalink Normal View History

2024-10-09 11:05:41 +00:00
<template>
<component :is="type" class="dynamic-component" :class="type.split('-')[1]" :data-name="type.split('-')[2]"></component>
2024-10-09 11:05:41 +00:00
</template>
<script>
let mod = []
// we autoload all components in form and nix-code folders
let comp = import.meta.glob('./{form,nix-code}/*.vue', { eager: true })
Object.entries(comp).forEach(([path, definition]) => {
let c = path.split('/');
const componentName = c[1]+'-'+c[2].replace(/\.\w+$/, '')
mod[componentName] = definition.default
})
// we autoload all custom components in form and nix-code custom folders
comp = import.meta.glob('../custom/components/{form,nix-code}/*.vue', { eager: true })
Object.entries(comp).forEach(([path, definition]) => {
let c = path.split('/');
const componentName = c[3]+'-'+c[4].replace(/\.\w+$/, '')
mod[componentName] = definition.default
})
2024-10-09 11:05:41 +00:00
export default {
components: {
...mod
2024-10-09 11:05:41 +00:00
},
props: {
type: { type: String, required: true },
2024-10-09 11:05:41 +00:00
},
}
</script>