Mark L. Reyes

Vue Components: Bootstrap Card, Github API

I’m dabbling with Vue version 3. Here’s Part 2 of 2 in generating a reusable component. This time with an API call attached.


Introduction

Let’s build this. A simple Vue app which accesses Github’s REST API and prints a user’s profile into a Bootstrap 4 card interface.

What’s the Goal?

Create a reusable component that displays a person’s Github profile.

What will we need?

Step By Step

Step 1: Create Vue App

Visit Stackblitz.com and click the Vue icon to automatically generate a default HelloWorld project.

Step 2: Install Dependencies

Enter additional dependencies such as axios and bootstrap (jquery and popper is optional but I added it anyway).

Step 3: Add Dependencies to main.js

const { createApp } = require("vue");
import App from "./App.vue";
import "bootstrap"; // Add this import.
import "bootstrap/dist/css/bootstrap.css"; // Add this import.

createApp(App).mount("#app");

Step 4: Create a Service for API Call

Create a new directory called services and add new file GithubAPI.js.

The Service Code

Debrief of the GithubAPI service code:

Step 5: Modify HelloWorld.vue Component

Out of box, Stackblitz generates a default Vue project paired with a component called HelloWorld.vue. Rename it.

We’ll repurpose most of this by first renaming it to GithubProfile.vue.

The Component Code

Debrief of the GithubProfile component code:

Debrief of the App component code:

Key Takeaways

We’ve now created a reusable component which is dynamic enough to apply a Bootstrap card by passing in the Github profile as a prop. This will use Github’s API to make a call on their end which will print the profile data to the card.

Additional Resources

Exit mobile version