nixin-web/components/DynamicComponent.vue

35 lines
940 B
Vue
Raw Normal View History

2024-10-09 11:05:41 +00:00
<template>
<component :is="type"></component>
</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
})
console.log(mod)
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>