nuxt / icon

The <Icon> component, supporting Iconify, Emojis and custom components.
https://stackblitz.com/edit/nuxt-icon-playground?file=app.vue
MIT License
883 stars 41 forks source link

Please add to readme file nuxt3 dynamic import #22

Closed ozgurkisa closed 1 year ago

ozgurkisa commented 1 year ago

Please add to readme file nuxt3 dynamic import example:

import { Icon } from "@iconify/vue"

function renderIcon(icon) {
  return () => h(Icon, { icon })
}

renderIcon('uil:github')
Atinux commented 1 year ago

What is the use case?

ozgurkisa commented 1 year ago

How to use Nuxt-Icon in Javascript? I need this to be able to use render. (nuxt h)

For example create a link element in icon:

   h(
      NuxtLink,
            { to: { path: toPath } },
            { default: () =>  h(Icon, { icon })}
     )
Atinux commented 1 year ago

Hi @ozgurkisa

You should be able to do:

<script setup>
import { Icon } from '#components'
const icon = ref('uil:github')

const MyIcon = h(Icon, { name: 'uil:twitter' })
</script>

<template>
  <p><MyIcon /></p>
</template>

I updated the playground: https://stackblitz.com/edit/nuxt-icon-playground?file=app.vue

Can you confirm it works for you?

ozgurkisa commented 1 year ago

Hi @ozgurkisa

You should be able to do:

<script setup>
import { Icon } from '#components'
const icon = ref('uil:github')

const MyIcon = h(Icon, { name: 'uil:twitter' })
</script>

<template>
  <p><MyIcon /></p>
</template>

I updated the playground: https://stackblitz.com/edit/nuxt-icon-playground?file=app.vue

Can you confirm it works for you?

Yes, thank u. It might be good for you to add this to the readme file.

Atinux commented 1 year ago

Done, thank you @ozgurkisa