Skip to content

Icon 图标

安装

  • pnpm i --save @fortawesome/vue-fontawesome
  • pnpm i --save @fortawesome/fontawesome-svg-core
  • pnpm i --save @fortawesome/free-solid-svg-icons

Use

在 main.js 中引入

js
import { library } from "@fortawesome/fontawesome-svg-core";
import { fas } from "@fortawesome/free-solid-svg-icons";
library.add(fas);

基础用法

<script setup>
import KIcon from "@/components/Icon/Icon.vue";
</script>
<template>
  <div>
    <k-icon icon="fa-bomb" :fade="true" type="primary" size="xl"></k-icon>
    <k-icon icon="fa-face-smile" type="success" size="xl"></k-icon>
    <k-icon icon="fa-poo" type="warning" size="xl"></k-icon>
    <k-icon icon="fa-ghost" type="danger" size="xl"></k-icon>
  </div>
</template>

更多图标参考 fontawesome 图标库 https://origin.fontawesome.com/docs

Attributes

属性名说明类型默认值
color颜色string
typeiconenum - 'primary'| 'success'| 'warning'| 'danger'| 'info'
size大小enum - '2xs' | 'xs' | 'sm' | 'lg' | 'xl' | '2xl' | '1x' | '2x' | '3x' | '4x' | '5x' | '6x' | '7x' | '8x' | '9x' |'10x''1x'
icon图标名称object | Array<string> | string | IconDefinition
fade显示隐藏动画booleanfalse

更多 icon 属性请查看

ts
interface FontAwesomeIconProps {
  border?: boolean;
  fixedWidth?: boolean;
  flip?: "horizontal" | "vertical" | "both";
  icon: object | Array<string> | string | IconDefinition;
  mask?: object | Array<string> | string;
  maskId?: object | Array<string> | string;
  listItem?: boolean;
  pull?: "right" | "left";
  pulse?: boolean;
  rotation?: 90 | 180 | 270 | "90" | "180" | "270";
  swapOpacity?: boolean;
  size?:
    | "2xs"
    | "xs"
    | "sm"
    | "lg"
    | "xl"
    | "2xl"
    | "1x"
    | "2x"
    | "3x"
    | "4x"
    | "5x"
    | "6x"
    | "7x"
    | "8x"
    | "9x"
    | "10x";
  spin?: boolean;
  transform?: object | string;
  symbol?: boolean | string;
  title?: string;
  titleId?: string;
  inverse?: boolean;
  bounce?: boolean;
  shake?: boolean;
  beat?: boolean;
  fade?: boolean;
  beatFade?: boolean;
  spinPulse?: boolean;
  spinReverse?: boolean;
}