【问题标题】:Vue 3 - dynamically bind font awesome iconsVue 3 - 动态绑定字体真棒图标
【发布时间】:2020-12-29 20:26:42
【问题描述】:

我有一个v-for 循环,其他一切似乎都在工作,但由于某种原因,该图标没有出现。

如何正确绑定?

注意:我还返回了图标并将其导入,并且已经在我的项目中使用了 font awesome,所以我知道它正在工作。问题是我如何绑定它。


进口:

import { ref } from '@vue/composition-api'
import {faCircle} from '@fortawesome/free-solid-svg-icons'

v-for循环:

<div
    class="m-auto w-full flex flex-col justify-center items-center"
>
    <div>
        <fa :icon="item.icon" class="text-5xl text-gray-400" />
        // the icon isn't showing but when I write {{item.icon}} I can see the text 'faCircle'
    </div>
    <div class="py-4 text-2xl font-semibold block">
        {{ item.title }}
    </div>
    <div class="px-10">
        <span class="text-base">
            {{ item.text }}
        </span>
    </div>
</div>

脚本:

export default {
  setup() {
    const items = ref([
      {
        title: 'bla',
        text: 'bla',
        icon: 'faCircle'
      },
      {
        title: 'bla',
        text: 'bla',
        icon: 'faCircle'
      },
      {
        title: 'bla',
        text: 'bla',
        icon: 'faCircle'
      }
    ])

我退回了物品:

return {
  faCircle,
  items
}

【问题讨论】:

标签: vue.js font-awesome


【解决方案1】:

所以我知道问题出在哪里。我把它写成一个字符串

脚本

   export default {
      setup() {
        const items = ref([
          {
            title: 'bla',
            text: 'bla',
            icon: 'faCircle'
          },
          {
            title: 'bla',
            text: 'bla',
            icon: 'faCircle'
          },
          {
            title: 'bla',
            text: 'bla',
            icon: 'faCircle'
          }
        ])

ICON 应该写成 WITHOUT 字符串,因为我们将它导入到表达式中

 {
    title: 'bla',
    text: 'bla',
    icon: faCircle
  }

【讨论】:

    猜你喜欢
    • 2016-02-10
    • 2022-01-18
    • 2021-10-24
    • 2014-01-16
    • 2014-05-09
    • 2021-10-02
    • 2013-12-07
    • 2017-05-02
    • 1970-01-01
    相关资源
    最近更新 更多