Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use <Component :is="" #260

Closed
5 tasks done
dev-vinicius-andrade opened this issue Jan 10, 2023 · 5 comments
Closed
5 tasks done

Unable to use <Component :is="" #260

dev-vinicius-andrade opened this issue Jan 10, 2023 · 5 comments

Comments

@dev-vinicius-andrade
Copy link

dev-vinicius-andrade commented Jan 10, 2023

Describe the bug

I'm currently using the plugin and now I need to create some components dynamically.

In my vite.config.ts I've the following configuration

import ViteIconsResolver from 'unplugin-icons/resolver';
//....
			resolvers: [
				ViteIconsResolver({
					componentPrefix: 'iconify',
					enabledCollections: ['fluent-emoji', 'fluent-emoji-flat', 'fa', 'mdi', 'line-md', 'flagpack', 'ic'],
				}),
			],

This allows me to use the component like

<template>
    <IconifyFaFacebookF :color="socialIconsColors" />
</template>

But currently i need to make it work more dynamicaly, like:

 <template>
    <Component v-for="(iconName,index) in availableIcons :color="socialIconsColors" />
</template>
<script setup lang="ts">
import {computed} from 'vue'
const availableIcons = computed(()=>['IconifyFaFacebookF','IconifyFaInstagram']);
</script>

But I can't get it to work. Is it possible?

Other thing is that i can't change the icons properties using :width and :height

Reproduction

Dynamicaly create icons based on a list of iconNames

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 14.32 GB / 31.91 GB
  Binaries:
    Node: 16.18.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.963.0), Chromium (108.0.1462.76), ChromiumDev (Hey friend

In an effort to grow oh-my-posh, the decision was made to no
longer support the PowerShell module. Over the past year, the
added benefit of the module disappeared, while the burden of
maintaining it increased.

However, this doesn't mean oh-my-posh disappears from your
terminal, it just means that you'll have to use a different
tool to install it.

All you need to do, is follow the migration guide here:

https://ohmyposh.dev/docs/migrating)
    Internet Explorer: 11.0.22621.1

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@dev-vinicius-andrade
Copy link
Author

any news regarding it?

@huluobotx
Copy link

I have got the same problem

  <template #title>
    <el-icon v-if="menu.meta.icon"><component :is="menu.meta.icon"/></el-icon>
    <span>{{ menu.meta.title }}</span>
  </template>
  <menu-item v-for="(item, key) in menu.children" :key="key" :menu="item" :basePath="pathResolve" />
</el-sub-menu>

It's not effect

@dev-vinicius-andrade
Copy link
Author

would be very nice having this feature

@Yiddishe-Kop
Copy link

Yiddishe-Kop commented Mar 3, 2023

Currently that auto-imports doesn't work with dynamic components, my workaround was to explicitly import dynamically used icons:

<template>
    <Component :is="component" />
</template>

<script setup>
import IconTablerHome from '~icons/tabler/smart-home'
import IconTablerListDetails from '~icons/tabler/list-details'
import IconTablerGift from '~icons/tabler/gift'

const props = defineProps({
    name: String,
    set: {
        type: String,
        default: 'tabler',
    },
})

const icons = {
    'tabler-home': IconTablerHome,
    'tabler-list-details': IconTablerListDetails,
    'tabler-gift': IconTablerGift,
}

const component = computed(() => icons[`${props.set}-${props.name}`])
</script>

@antfu
Copy link
Member

antfu commented Mar 3, 2023

#5 (comment)

Please search for existing issues before creating one.

@antfu antfu closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants