Created
August 22, 2023 11:01
-
-
Save xiCO2k/cf84506dfa24f8422086d2038167c49c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<script setup> | |
import { reactive, onMounted } from 'vue'; | |
const props = defineProps({ | |
is: String, | |
icons: Array, | |
}); | |
const list = reactive({}); | |
onMounted(() => { | |
const all = import.meta.glob('./Icons/*.vue'); | |
(props.icons || [props.is]).forEach(async icon => { | |
list[icon] = await load(all, icon); | |
}); | |
}); | |
const load = async (all, icon) => { | |
const component = all[`./Icons/${icon}.vue`]; | |
if (!icon || !component) { | |
return; | |
} | |
return (await component()).default; | |
}; | |
</script> | |
<template> | |
<Component :is="list[is]" /> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment