Home

Awesome

Oh, Vue Icons!

npm downloads license

English | 中文说明

A Vue component for including inline SVG icons from different popular icon packs easily.

 

Features

 

Supported Icon Packs

Now the following 20 icon packs are supported:

Icon PackPrefixLicenseCounts
academiconsaiSIL OFL 1.1149
Bootstrap IconsbiMIT1668
CoreUI Icons Free (Colorful)coCC BY 4.0 License1575
Cryptocurrency Icons (Colorful)ciCC0 1.0 Universal942
Font Awesome 5 FreefaCC BY 4.01610
Flat Color Icons (Colorful)fcMIT / Good Boy329
Flag Icon (Colorful)fiMIT530
gameiconsgiCC BY 3.04052
HeroiconshiMIT460
IoniconsioMIT1332
Line AwesomelaMIT / Good Boy1544
Material Design iconsmdApache 2.010537
OcticonsoiMIT259
Pokemon Icons (Colorful)piCC BY 4.01453
PrimeIconsprMIT238
PixelarticonspxMIT460
Remix IconriApache 2.02271
Simple IconssiCC0 1.0 Universal2233
VSCode Icons (Colorful)viCC BY-SA 4.01125
Weather IconswiSIL OFL 1.1219

 

Documentation

Search for icons and view the documentation here.

 

Installation

yarn add oh-vue-icons
# or
npm install oh-vue-icons

For Vue 2, you'll also need @vue/composition-api:

yarn add @vue/composition-api -D

Or if you are using Nuxt 2, you'll need @nuxtjs/composition-api instead:

yarn add @nuxtjs/composition-api -D

then add @nuxtjs/composition-api/module to the buildModules option in your nuxt.config.js, see here for details.

 

Import

Global Import

Import oh-vue-icons and install it into Vue in main.js. You can only import the icons you need to reduce the bundle size.

From v1.x, this library works for both Vue 2 & 3 within a single package.

Vue 3

// main.js
import { createApp } from "vue";
import App from "./App.vue";

import { OhVueIcon, addIcons } from "oh-vue-icons";
import { FaFlag, RiZhihuFill } from "oh-vue-icons/icons";

addIcons(FaFlag, RiZhihuFill);

const app = createApp(App);
app.component("v-icon", OhVueIcon);
app.mount("#app");

If you don't care about the bundle size and want to import a whole icon pack, you may should:

// main.js
// import Font Awesome
import * as FaIcons from "oh-vue-icons/icons/fa";

const Fa = Object.values({ ...FaIcons });
addIcons(...Fa);

Vue 2

// main.js
import Vue from "vue";
import App from "./App.vue";

import { OhVueIcon, addIcons } from "oh-vue-icons";
import { FaFlag, RiZhihuFill } from "oh-vue-icons/icons";

addIcons(FaFlag, RiZhihuFill);

Vue.component("v-icon", OhVueIcon);

new Vue({
  render: h => h(App)
}).$mount("#app");

 

Local Import

import OhVueIcon from "oh-vue-icons";

export default {
  components: {
    "v-icon": OhVueIcon
  }
};

 

Usage

The icon names should be passed using kebab-case.

<template>
  <div>
    <v-icon name="fa-flag" />
    <v-icon name="ri-zhihu-fill" />
  </div>
</template>

For Font Awesome 5 icons, icons from regular pack have name prop values like fa-regular-flag. Icons from solid and brands pack have name prop values like fa-beer and fa-github.

See the documentation for more about the usage.

 

Props

NameDescriptionTypeAccepted ValuesDefault value
scaleIcon sizenumber/1
animationType of animationstringwrench / ring / pulse / spin / spin-pulse / flash / float/
speedAnimation speedstringslow / fast/
hoverEnable animation only when being hoveredbooleantrue / falsefalse
flipUsed to flip iconstringvertical / horizontal / both/
fillFill color of iconstringHEX color code or color namecurrentColor
labelIcon lablestring//
titleIcon titlestring//
inverseMake icon color white?booleantrue / falsefalse

Some examples could be found in the documentation.

 

Nuxt

When using Nuxt, you need to register oh-vue-icons as a plugin following Nuxt's documentation.

It should be noted that, oh-vue-icons should be added to the build.transpile option in your nuxt.config.js (see here for details):

export default {
  // ...
  build: {
    transpile: ["oh-vue-icons"]
  }
}

To render the icon component only on client-side, you may need to wrap it in a <client-only> tag:

<template>
  <div>
    <client-only>
      <v-icon name="fa-flag" />
      <v-icon name="ri-zhihu-fill" />
    </client-only>
  </div>
</template>

 

Vite

When using Vite, it is suggested to exclude oh-vue-icons from pre-bundling (see #20 for details):

// vite.config.js

export default {
  // ...
  optimizeDeps: {
    exclude: ["oh-vue-icons/icons"]
  }
}

When using Vite's Server-Side Rendering (SSR) support (VuePress, Vite SSG, etc.), oh-vue-icons should be added to the ssr.noExternal option (see here for details):

// vite.config.js

export default {
  // ...
  ssr: {
    noExternal: ["oh-vue-icons"]
  }
}

 

Contributing

Contributions are welcomed, see the contribution guides.

 

Acknowledgements

 

License

This project is MIT licensed. Icons are taken from other projects, so check the license of each accordingly.