Vue 3 使用FontAwesome

  1. 安装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
    
  2. 在中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);`
    
  3. 全局注册font-awesome-icon组件:
    import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";

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

  4. 在src/App.vue中使用这样的组件(请注意,图标名称是phone,不是faPhone):

    <font-awesome-icon :icon="['fas', 'phone']" />
    <font-awesome-icon icon="phone" />
    
  5. 显示图标

    image-20210429093539203

posted @ 2021-04-29 09:41  MarkYUN  阅读(1730)  评论(0编辑  收藏  举报