How to add a button with an icon in Bootstrap VueJS?

Hi Friends 👋,

Welcome To SortoutCode! ❤️

Add a button with an icon using BootstrapVue.We are using the b-button component for buttons and for icons we are using the b-icon component in BootstrapVue.

Today I am going to show you How you add a button with an icon using BootstrapVue in VueJS?

Table of contains

  • Setup the Vue.js
  • Install the Bootstrap and BootstrapVue
  • Create FirstComponent.vue and import it into App.js
  • Show the b-icon component
  • Add a button with an icon

Let’s start today’s tutorial How do I add a button with an icon using BootstrapVue in VueJS?

Setup the Vue.js

First, we have to install the Vue project, I had installed the vueJS in my system. If you haven’t installed or have any problem with installation you can follow this article, which will show you step by step process of installation.

How to Install the VueJS project?

Install the Bootstrap and BootstrapVue

First, we have to install the Vue project, I had installed the vueJS in my system. If you haven’t installed or have any problem with installation you can follow this article, which will show you step by step process of installation. In that article, I had also show you how to install BootstrapVue in your vue.js project step by step.

How to install or configure vue-bootstrap in VueJS?

Create FirstComponent.vue and import it into App.js

Create the new component into src/components/ components folder.the component name is FirstComponent.vue and import into App.js file:

App.js

<template>
  <div id="app">
    <FirstComponent />
  </div>
</template>

<script>
import FirstComponent from "./components/FirstComponent.vue";
export default {
  name: "App",
  components: {
    FirstComponent,
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

Show the b-icon component

After vue-bootstrap installation and setup, I’m going to show you How to use the icon in BootstrapVue, as mentioned above here, I’m going to use the b-icon component on vue-bootstrap.

Let’s start today’s tutorial on how do you add bootstrap icons in BootstrapVue.

FirstComponent.vue

<template>
  <b-container>
    <b-row class="mt-5">
      <b-col>
        <b-icon icon="gear-fill"></b-icon>
        <b-icon icon="person-fill"></b-icon>
        <b-icon icon="inbox-fill"></b-icon>
      </b-col>
    </b-row>
  </b-container>
</template>

<script>

export default {
  name: "FirstComponent",
};
</script>

Output

bootstrap vue icon

Add button with icon

I’m going to add a button with an icon in BootstrapVue. Let’s see the code:

FirstComponent.vue

<template>
  <b-container>
    <b-row class="mt-5">
      <b-col>
        <b-button variant="outline-primary"><b-icon icon="gear-fill"></b-icon> Settings</b-button>
        <b-button variant="outline-primary"><b-icon icon="person-fill"></b-icon> Profile</b-button>
        <b-button variant="outline-primary"><b-icon icon="inbox-fill"></b-icon> Message</b-button>
      </b-col>
    </b-row>
  </b-container>
</template>

<script>

export default {
  name: "FirstComponent",
};
</script>

For now, let’s check the output.

bootstrap vue button with icon

All the best 👍.

Follow me on Twitter