Theme
Primary Color

استخدام FontAwesome Icons داخل تطبيق Vue.js

هنضيف أيقونات للعرض والتعديل والحذف داخل تطبيق Vue 3

هنستورد الأيقونات المطلوبة فقط من مجموعة Regular

تثبيت الحزم

هنحتاج المكتبة الأساسية وحزمة أيقونات Regular وال Component المخصصة ل Vue 3

npm install @fortawesome/fontawesome-svg-core @fortawesome/free-regular-svg-icons @fortawesome/vue-fontawesome@latest-3

تسجيل ال Component والأيقونات

في نقطة تشغيل التطبيق نضيف الأيقونات لل library ونسجل ال Component قبل mount

المثال يفترض وجود ال Component الرئيسية App.vue وعنصر الصفحة #app

App.vue
import { createApp } from "vue";
import App from "./App.vue";
import { library } from "@fortawesome/fontawesome-svg-core";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { faEye, faPenToSquare, faTrashCan } from "@fortawesome/free-regular-svg-icons";

library.add(faEye, faPenToSquare, faTrashCan);

const app = createApp(App);
app.component("font-awesome-icon", FontAwesomeIcon);
app.mount("#app");

عرض الأيقونات

ال far بتحدد مجموعة Regular والاسم الثاني بيحدد الأيقونة

التسجيل على مستوى التطبيق بيسمح باستخدام ال Component داخل ال Templates

<template>
  <div>
    <font-awesome-icon :icon="['far', 'eye']" />
    <font-awesome-icon :icon="['far', 'pen-to-square']" />
    <font-awesome-icon :icon="['far', 'trash-can']" />
  </div>
</template>

إضافة أيقونة جديدة

مثلا لإضافة أيقونة صورة نستورد faImage من نفس الحزمة ونضيفها لل library قبل تشغيل التطبيق

السطران دول إضافة على كود التسجيل السابق

import { faImage } from "@fortawesome/free-regular-svg-icons";

library.add(faImage);
<font-awesome-icon :icon="['far', 'image']" />

استخدام الأيقونة داخل زر

لو الأيقونة لوحدها داخل زر لازم نوضح وظيفة الزر باسم مفهوم

ال aria-label بتوفر الاسم لأدوات قراءة الشاشة

<button type="button" aria-label="Delete Item">
  <font-awesome-icon :icon="['far', 'trash-can']" />
</button>