Vue 3 使用FontAwesome
-
安装prelease的vue-fontawesome,这与3的Vue,图标依赖性兼容:
npm i --save @fortawesome/vue-fontawesome@prerelease npm i --save @fortawesome/fontawesome-svg-core npm i --save @fortawesome/free-solid-svg-icons
-
在中main.js,选择@fortawesome/free-solid-svg-icons要加载的图标:
import { library } from "@fortawesome/fontawesome-svg-core";
import { faPhone } from "@fortawesome/free-solid-svg-icons";
` library.add(faPhone);`
-
全局注册font-awesome-icon组件:
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
createApp(App).component("font-awesome-icon", FontAwesomeIcon) .mount("#app");
-
在src/App.vue中使用这样的组件(请注意,图标名称是phone,不是faPhone):
<font-awesome-icon :icon="['fas', 'phone']" /> <font-awesome-icon icon="phone" />
-
显示图标