ionic-frameworkvuejs2ioniconsionic-vue

Ionic-Vue Ionicons 5.x.x doesn't show icon


I used ionic-vue with ionicons 5.0.1 but after call

<ion-icon name="add"></ion-icon>

i was following https://dev.to/aaronksaunders/build-your-first-ionic-vue-app-18kj and https://github.com/ionic-team/ionic/issues/19078 tutorial, but stucked and icon in FAB cannot be show. This is my syntax, thank you for helping.

<template>
   <ion-page>

        ....

        <ion-fab vertical="bottom" horizontal="end" slot="fixed">
            <ion-fab-button @click="$router.push({ name: 'new-item' })">
                <ion-icon name="add"></ion-icon>
            </ion-fab-button>
        </ion-fab>
        </ion-content>
    </ion-page>
</template>

<script>

...

import { addIcons } from 'ionicons';
import * as allIcons from 'ionicons/icons';

const currentIcons = Object.keys(allIcons).map(i => {
  const key = i.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)
  if(typeof allIcons[i] === 'string') {
    return {
      [key]: allIcons[i],
    }
  }
  return {
    ['ios-' + key]: allIcons[i].ios,
    ['md-' + key]: allIcons[i].md,
  };
});

const iconsObject = Object.assign({}, ...currentIcons);
addIcons(iconsObject);

...
</script>

Result FAB does not show icon 'add':

enter image description here


Solution

  • For Ionic Vue 3 using Composition API:

    <template>
      <ion-icon :icon="rocket" />
    </template>
    
    <script>
    import { IonIcon } from '@ionic/vue';
    import { rocket } from 'ionicons/icons';
    
    export default {
      components: { IonIcon },
      setup() {
        return {
          rocket
        }
      }
    }
    </script>
    

    For <script setup>

    <script setup>
    import { IonIcon } from '@ionic/vue';
    import { rocket } from 'ionicons/icons';
    </script>
    
    <template>
      <ion-icon :icon="rocket" />
    </template>