2022-09-01 22:32:03 +00:00
|
|
|
<script setup lang="ts">
|
2022-09-09 22:46:53 +00:00
|
|
|
import type { Ref } from "vue";
|
|
|
|
import type { IconifyIcon } from "@iconify/vue";
|
|
|
|
import { Icon as Iconify, loadIcon } from "@iconify/vue";
|
2022-09-01 22:32:03 +00:00
|
|
|
|
|
|
|
const nuxtApp = useNuxtApp();
|
|
|
|
const props = defineProps({
|
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const icon: Ref<IconifyIcon | null> = ref(null);
|
|
|
|
const component = computed(() => nuxtApp.vueApp.component(props.name));
|
|
|
|
|
2022-09-09 22:46:53 +00:00
|
|
|
icon.value = await loadIcon(props.name).catch(() => null);
|
2022-09-01 22:32:03 +00:00
|
|
|
|
|
|
|
watch(
|
|
|
|
() => props.name,
|
|
|
|
async () => {
|
2022-09-09 22:46:53 +00:00
|
|
|
icon.value = await loadIcon(props.name).catch(() => null);
|
2022-09-01 22:32:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-09-05 00:37:37 +00:00
|
|
|
<Iconify v-if="icon" :icon="icon" class="inline-block" />
|
2022-09-01 22:32:03 +00:00
|
|
|
<Component :is="component" v-else-if="component" />
|
|
|
|
<span v-else>{{ name }}</span>
|
|
|
|
</template>
|