Dynamic import
<!-- ✅ this will work (string) -->
<UIcon name="close" />
<!-- ✅ this will work too (ternary operator with strings) -->
<UIcon name="isOpened ? 'arrow_up' : 'arrow_down'" />
<!-- 🛑 this won't work (variable) -->
<UIcon :name="stateIcon" /><script setup>
import { computed } from "vue";
/* here is the trick */
const icons = {
iconArrowUp: "arrow_up",
iconArrowDown: "arrow_down",
}
const stateIcon = computed(() => isOpened ? icons.iconArrowUp : icons.iconArrowDown);
</script>
<UIcon :name="stateIcon" />Icons safelisting
Last updated