Skip to content

Instantly share code, notes, and snippets.

@xiCO2k
Created August 22, 2023 11:01
Show Gist options
  • Save xiCO2k/cf84506dfa24f8422086d2038167c49c to your computer and use it in GitHub Desktop.
Save xiCO2k/cf84506dfa24f8422086d2038167c49c to your computer and use it in GitHub Desktop.
<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