Author Archives: Mark Reyes

About Mark Reyes

Web Developer based out of Southern California.

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?

  • Stackblitz – to quickly prototype a Vue project and its dependencies.
  • Bootstrap 4 – to grab some ready-made user interfaces (e.g. cards).
  • Axios – the promise based library we’ll use to communicate with Github’s API.
  • Github API – the data source we’ll need to access and display a user’s profile.

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:

  • Line 1: Import axios library for promise based HTTP requests.
  • Line 5: Write a function called getGithubProfile() and pass in username as an argument.
  • Line 7: Leverage the get method and concatenate the username variable.
  • Line 9: Return the response object (component will consume this).

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:

  • Lines 3-16: The Bootstrap card.
  • Line 20: Import the service made from Step 4.
  • Lines 23-28: The prop you’ll pass in (e.g. a profile name).
  • Lines 29-33: Setup Vue’s data object which will populate the card.
  • Lines 34-42: Setup the API call inside of the created lifecycle hook.

Debrief of the App component code:

  • Line 13: the prop passed in as a string (e.g. my profile name).

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

Vue Components: Bootstrap Alerts

I’m dabbling with Vue version 3. Here’s Part 1 of 2 in generating a reusable component.


Introduction

Let’s build this. A simple Vue app which demonstrates a reusable notification by way of Bootstrap 4 alerts.

What’s the Goal?

Create a reusable component that displays different types of notifications.

What will we need?

  • Stackblitz – to quickly prototype a Vue project and its dependencies.
  • Bootstrap 4 – to grab some ready-made user interfaces (e.g. alerts).

Step By Step

Step 1: Create Vue App

Step 2: Install Dependencies

Enter additional dependencies such as 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: Modify HelloWorld.vue Component

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

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

The Component Code

Debrief of the Notifications component code:

  • Line 2: class binding is assigned passing in a type object.
  • Line 3: apply a slot so HTML can be used in full.
  • Lines 13-15: the prop defined to pass in what type of alert to display.

Debrief of the App component code:

  • Lines 12-14: type attribute will pass in the specific bootstrap class to style the alert.
  • Line 13: the HTML from here will be inserted to the slot assigned in the Notifications component.

Key Takeaways

We’ve now created a reusable component which is dynamic enough to apply Bootstrap’s variety of alerts as well as the ability to pass in a message with full HTML by way of slots.

Additional Resources

Mahalo and Aloha 2020

Dear 2020,

I had to be sure. I had to be sure to not write this in advance because I needed definitive proof that you were effectively put to rest. And here I am. Alive, but with scars nonetheless. And the impact you caused mankind over the last 12 months can only be so coldly explained as, it is what it is.

But YOU for sure…were the cruelest of moments. I thank my lucky starts that I didn’t fall into quicksand because it very much felt like the world was disappearing right beneath me. Our response to adversity is what will define our generation. And thus far, despite the chaos, I do very much see light at the end of this tunnel. And I am at peace knowing things will never be the same…again.

It honestly baffles me. Pages from MCU forced its way into our reality. I’d be lying if I said Thanos had nothing to do with this horrific year. Spearheaded by a global pandemic, a recession, civil unrest and political divide you forced me to either do nothing…or choose a side.

So let it be known that today…I’ve chosen.

I choose to be David rather than Goliath. Live and let live. I choose to accept that tribalism will always exist and to read between the lines, rather than judging an article by its title. I will show up each and every day, to try and fail rather than not trying…at all.

I’m here to look at my family and friends as family and friends again, rather than family and friends that voted for him or her. I choose to trust the results from observations and experiments over a period of time. But I have no shame in admitting that I’ll look up at the heavens for a bit more.

This past year has been too much for me to comprehend. But TLDR is a short-sighted technique in understanding just what the fuck happened in the last 365 days. Although once again, Einstein would enforce that time is simply relative, today is the day I disagree.

Today is officially my Day 1. There will be no other Day 1. This is it. And whatever becomes of it from this day forward will also be it is what it is but with one silver lining attached. I will always remember the struggles and hardships made, carry its pain and see it through.

As long as I am of sound mind and body, I will continue.

Mahalo and Aloha, 2020 🤙🏾