0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【vue.js】Font awesomeのアイコンを並べる【データバインディング】

Posted at

環境

Vue.js 6.14.9
Vue CLI 4.5.9

Font awesomeを利用

Font awesome を Vue.js で使ってみよう
VueでFont awesomeを利用する方法はこちらを参照させていただきました。

アイコンを並べる

まず参照通り表示してみました。

About.vue
<template>
  <div class="about">
    <font-awesome-icon icon="coffee" />
  </div>
</template>

ここから、次にv-forを使って、アイコンを複数並べたいと思います。

About.vue
<template>
  <div class="about">
    <div class="item" v-for="(data, index) in hoge" :key="index">
      <font-awesome-icon :icon="{{data.icon}}" />
    </div>
  </div>
</template>

scriptも記述していきます。

About.vue
<script>
  export default {
    data(){
      return {
        hoge: [
        {icon: "coffee"},
        {icon: "users"}
      ]};
    }
  };
</script>

あれ、エラーが、、、
スクリーンショット 2021-03-21 15.17.13.png
上記のエラーをみると、
icon="{{data.icon}}"の代わりに、icon="data.icon"を使ってねと書いてあるので、修正します。

About.vue
<template>
  <div class="about">
    <div class="item" v-for="(data, index) in hoge" :key="index">
      <font-awesome-icon :icon="data.icon"/ >
    </div>
  </div>
</template>

これでエラーは解消できました。

↓こんなふうにアイコンを並べることができました!!
スクリーンショット 2021-03-21 14.51.04.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?