Lessons learned from overbuilding a simple web app

In this article I want to share my experience, on what I learned from building a simple web application, and overwhelming it with unnecessary features. First and foremost, I’m still in college, so…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Step 3

In part one of this tutorial I introduced Vue and we learned how to setup and create a simple app in vue. If you haven’t read that, here is the link.

Put the json file in src/assets folder

Hello.vue is a Vue component file inside src/components. Components are one of the most powerful features of Vue. They help you extend basic HTML elements to encapsulate reusable code. At a high level, components are custom elements that Vue’s compiler attaches behaviour to.

If you’re familiar with React or Angular2, the idea of components and passing state won’t be new to you. In case you’re not, let’s go through some of the main concepts.

Websites large and small are usually composed of different pieces, and abstracting them into smaller pieces makes them easy to structure, reason about, reuse, and makes our code more legible. Instead of digging through all of the markup in long, multi-faceted page, we could comprise it of components.

OK, now fall back to our webapp.

In Hello.vue file I changed the lines between script tags as shown above.

First, import json data. Then inside default{} set name for your component and inside data(){}, put the imported json.

And that’s the end of step 3.

Vue.js uses an HTML-based template syntax that allows you to declaratively bind the rendered DOM to the underlying Vue instance’s data. All Vue.js templates are valid HTML that can be parsed by spec-compliant browsers and HTML parsers.

Under the hood, Vue compiles the templates into Virtual DOM render functions. Combined with the reactivity system, Vue is able to intelligently figure out the minimal amount of components to re-render and apply the minimal amount of DOM manipulations when the app state changes.

Directives are special attributes with the v- prefix. Example:

Here, the v-if directive would remove/insert the <p> element based on the truthiness of the value of the expression seen.

In our component, the template looks like this:

Chill! I’ll explain. First, create a div to hold all our contents. Then we have these 2 parts to write.

We have 5 objects in our Json array. So first we open a ul tag and inside it write a general li tag to render all 5 objects.

The v-for directive will loop through all elements in our array and create a li for each one of them. Now using the mem object we can access the contents of the Json object.

At this point we have access to every object through mem object. So now lets write code to render each data accordingly.

First one is the profile image:

The :src is shorthand for vue directive.

Second, is names, roles and stuff:

Third one is hyperlinks to social media profiles:

In all the above code snippets we used vue directives to access data from our vue instance.

OK, that concludes step 4.

Put some styles as you like.

Now the whole file looks like this:

That’s it, mission accomplished.

Now run the dev server and test the app. In the project folder type the following.

To build for production:

Happy Coding 💻

Add a comment

Related posts:

1. Limit Alcohol Intake

Your loved one may reduce his or her risk of breast cancer by controlling some factors. Your loved one may not control all factors in a breast cancer but she may manage a few. Breast cancer is one of…

Explore The Web Searching API And Power Up Your Website

Do you need to enrich your website or app with web searches? Keep reading to find out about the API that will power up your website. Web search engines are a crucial component of the Internet…

One Failing Unit Test

Currently I am working in a project as QA where we are doing re-modelling of SQL database to a new shiny Graph DB and writing a new rest service on top of it. Greenfield “yay” . I have been hearing a…