如何在vue js中创建fontawesome本地模板?

yc0p9oo0  于 2023-03-09  发布在  Vue.js
关注(0)|答案(1)|浏览(125)

我试图创建一个本地字体模型,以便能够将其导入到我的vuejs应用程序中,但我没有成功,有人能帮助我吗?
字体.js

import { library } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faUserSecret } from '@fortawesome/free-solid-svg-icons'

library.add(faUserSecret)

export default [library, FontAwesomeIcon, faUserSecret] 

main.js
import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'

import './assets/main.css'

import library from './models/fontAwesome'

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.component('font-awesome-icon', library)
app.mount('#app')`your text``
6tdlim6h

6tdlim6h1#

我通过创建一个Vue插件解决了这个问题。希望这能有所帮助。

Icon.js

import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faUserSecret } from '@fortawesome/free-solid-svg-icons'

export default {
  install(Vue){
     library.add(faUserSecret)
     Vue.component('FaIcon', FontAwesomeIcon)
  }
}

main.js
import Icon from '/path/to/Icon.js'
.
.
.

app.use(Icon)

相关问题