Building a simple data filtering app with Vue js

John Ayeni
May 9, 2018 · 13 min read

See more awesome technical articles on my dev blog,

Vue js, The Progressive JavaScript Framework

Vue (pronounced /vjuː/, like view) is a progressive framework for building user interfaces. Unlike other monolithic frameworks, Vue is designed from the ground up to be incrementally adoptable. The core library is focused on the view layer only, and is easy to pick up and integrate with other libraries or existing projects. On the other hand, Vue is also perfectly capable of powering sophisticated Single-Page Applications when used in combination with modern tooling and supporting libraries.

Vuejs was developed by Evan You, an ex-Google software engineer. Just before launching Vuejs 2.0, he started to work on Vue.js full time and as a result, Vue.js 2 is now significantly lighter, smaller in size and faster. Currently, many popular products use Vuejs to build their user interfaces. Such platforms include Laravel Spark, Grammarly, Statamic, Laracasts and more. There is a comprehensive list of projects using Vuejs on Github. Vuejs 2’s documentation is very detailed, and there is a vibrant community of users. Before we begin lets get familiar with some common concepts in Vue.


Vuejs 2 is similar to React and Angular 2 in a few ways. There are few key concepts that will help you get started easily. I’ll give a basic overview of these concepts to nourish your understanding of Vuejs. This explanation is all thanks to Prosper Otemuyiwa Tutorial for Vue js 2 Authentication with Auth0. You can find the tutorial here

They are:

  • Directives
  • Components
  • Template/JSX

You can decide to use Vuejs 2 by simply invoking methods on a Vue instance or go the component-composing route.

<div id="app">   
<p>{{ message }}</p>

The result of the code above on the browser will be Hello, it is this easy!. The value of any property in the data object within a new Vue instance will be rendered to the DOM easily. The curly braces are used to display the property on the web page.


It’s very easy to toggle the display of items on a web page with inbuilt directives such as v-if, v-show like so:

<div id="app">
<p v-if="visible()">{{ message }}</p>

If for any reason, the visible function returns false, the paragraph would not be displayed on the web page. What about iterations and loops? Check out the code below

<div id="app">
<li v-for="item in items">
{{ }}

On the page, it will simply display:

Vue js
Angular js
React js


Vuejs 2 also leverages components. It allows you to build large applications composed of small, self-contained smaller components.

An example of a component is an HTML5 tag, say <header>. A header can have attributes, it can be styled and also possess its own behaviour. In Vuejs 2, you'll be able to build your own custom component by registering it like so:

Vue.component('app-header', {
template: "<li>This is the application's header</li>"

Then, you can use it in another component like so:


Vuejs 2 provides some methods that are triggered at various points from creating a component up until the component is destroyed. This is called the Instance Lifecycle, also known as the Component’s Lifecyle. Each Vue instance goes through a series of initialization steps when it is created — for example, it needs to set up data observation, compile the template, mount the instance to the DOM, and update the DOM when data changes. So you can execute custom logic in these hooks. These lifecycle hooks are beforeCreate, created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy and destroyed.

Vuejs 2 Lifecycle hooks

  • beforeCreate() : This method is called synchronously after the Vue instance has just been initialized, before data observation and event/watcher setup.
  • created() : This method is called synchronously after the Vue instance is created. Data observation, computed properties, methods and event callbacks have already been set up at this stage but the mounting phase has not started yet.
  • beforeMount() : This method is called right before the component is mounted. So it is called before the render method is executed.
  • mounted() : This method is called after the component has just been mounted.
  • beforeUpdate() : This method is called when the data changes, before the virtual DOM is re-rendered and patched.
  • updated() : This method is called after a data change causes the virtual DOM to be re-rendered and patched.
  • activated() : This method is called when a kept-alive component is activated.
  • deactivated() : This method is called when a kept-alive component is deactivated.
  • beforeDestroy() : This method is called right before a Vue instance or component is destroyed. At this stage the instance is still fully functional.
  • destroyed() : This method is called after a Vue instance or component has been destroyed. When this hook is called, all directives of the Vue instance have been unbound, all event listeners have been removed, and all child Vue instances have also been destroyed.

Vuejs 2 possess some built-in components such as component, transition, transition-group, keep-alive and slot. You can take advantage of these components in your app. Check out how to use them.


Props is the short form for properties. Properties are attributes of a component. In fact, props are how components talk to each other. A tag in HTML such as <img> has an attribute, a.k.a prop called src that points to the location of an image.

In Vue.js 2, you can pass data from the parent scope into child components. A typical example is this:

Vue.component('tag-list', {
props: ['item'],
template: '<li></li>'

It will display these items on the web page like so:

guardians of the galaxy

Template / JSX

Vue.js 2 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.

You can also decide to use JSX. JSX is the combination of HTML and JavaScript code in the same file. The browser is not meant to understand it. It must first be transpiled into standard JavaScript before the browser can understand. An example of JSX usage in Vuejs is:

data: {
text: 'Hello world'
render (h) {
return (
<div id='message'>
{ this.text }

Now, by default, Vue doesn’t support JSX, but with the help of babel-plugin-transform-vue-jsx we can use JSX with Vue. Oh, the ecosystem should be thanked for this great tool. Whoop! Whoop!

With Vue 2, you can use the render function to create a reactive element. And you can use JSX in it like so:

new Vue({
el: '#app',
data: {
msg: 'Click to see the message.'
methods: {
hello () {
alert('This is the message.')
render: function render(h) {
return (
on-click={ this.hello }
{ this.msg }

Can you see the power of JSX manifesting itself in Vue? Awesome, you can check out more information on JSX in Vue here.

Next, let’s build an application with Vuejs 2.


Note that for this app, we are going to be using definitive data, meaning we already know what we are filtering so that app will be tailored based on the data we have. The main aim of this tutorial is to touch basic major concepts in Vue js. For this we are going to be using vue-cli. Vue.js provides an official CLI for quickly scaffolding ambitious Single Page Applications. It provides batteries-included build setups for a modern frontend workflow. It takes only a few minutes to get up and running with hot-reload, lint-on-save, and production-ready builds. First of all make sure you have Node js installed on your machine. You can get that here.

Next create a folder for your Vue apps and open a terminal on it. Install vue-cli globally using this command

npm install --global vue-cli

Then use vue-cli to scaffold your application

vue init webpack filter-app

The set up should ask you a couple of questions. Decline for tests . We do not need them for this tutorial. You can learn about them later. Then navigate into your project folder and serve the app

cd filter-app
npm run dev

The initial setup for the project would have asked you if you wanted to do an npm install , but just incase the serving of the app gives an error just enter npm install as a command. After the app is served, it should tell you the url to access the app. Just go to the url on your browser and you should see the app.

Let’s check out the structure of our newly scaffolded app.

build/ - All build files are here
config/ - All environment config files are here
node_modules/ - All the packages required for the vuejs app resides here
- assets - All assets reside here
- components - All our Vue components resides here
- router - Our router is defined here
- App.vue - The Parent component
- main.js - Starting point for our app where the router, template and App component are bound to the root app div
static/ - contains static files
index.html - Index file that declares the root div where the App component is been bound to
package.json - File that contains the names of all the packages residing in node_modules folder
node_modules/ - All the packages required for the react app resides here
package.json - File that contains the names of all the packages residing in node_modules folder

We will work with this structure but make some few modifications.

Create a data folder in the src folder and create a file in it named data.js. Open the file up and add this code to it

const data = [

This will serve as our data for the app

Now to create the components we need. Delete the HelloWorld.vue file in the components/src folder and add create this two files SearchPage.vue and ItemCard.vue . Please note that file names are case sensitive.

Also for the design, we are going to be using bootstrap 4 and Fontawesome icons. So we are just going to add CDN links to the index.html file to which our app builds to which is located in the root folder. So our index.html file should look like this

<!DOCTYPE html>

Next to the routing. For this app we only have one route which is the root route(trailing slash route). The only thing we have to change though is the component in which that route renders which will be our SearchPage.vue component. If you want to know more about routing in Vue js, Read more on it here. Now open up the index.js file in the router folder and edit to this

import Vue from 'vue';

What we have just done is to set the app to render the Search Page component on when on the root route. Now to the main thing. Making our search page. before we do that, remember the Itemcard.vue file we created. This component is meant to be for each item we display from our data. For each item we are going to make them cards. Ad this code to the ItemCard.vue file


Next is to create our search page component. Now basically, let me give tell you the list of things we need this component to do and have

To have
- A search bar where a data keyword can be typed in
- A group of checkboxes for filters
- Display of all data depending on the the search key word and filters selected

Now that we know what we need we can go ahead to write the code we need for it. This code will go to the SearchPage.vue file we created in the src/components folder


So basically the way this component works is that when its mounted, it fetches data which will return all data available since there is no search key word or any filters selected. Each checkbox input is tied down to to a model, which in this case is one stack. Each time any checkbox changes it triggers the getfilteredData function. Same also with the search bar. The getfilteredData function is also triggered on keyup.

One last thing, open up your App.vue file in the src folder and edit its contents to this


Now make sure your app is still serving, if not fire it up again and check your browser. Everything should work fine and you should have this

Cool right ??

Play around with the app. You can make modifications as you like to add more cool features to the search and make it more dynamic. Get the full code of the app here on Github. We’re done, “adios amigos”.

See more awesome technical articles on my dev blog,

Covenant University Developers Community

CDC is tasked with helping Covenant University students learn Software Development and linking them up with opportunities in the industry. This is our official blog where we document our thoughts as we learn and gain more experience.

John Ayeni

Written by

Software Engineer, Udacity Mobile Web Specialist, Writer and Designer

Covenant University Developers Community

CDC is tasked with helping Covenant University students learn Software Development and linking them up with opportunities in the industry. This is our official blog where we document our thoughts as we learn and gain more experience.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade