Project 6: Vue Introduction
05 Dec 2016I’ve read many posts about about Vue.js over the last several weeks. The framework looks like it’ll fulfill many of my needs at work. Over the next several weeks I’m going to work on figuring out the nuances of setting up fullstack web applications with Vue as my view library.
My go to website for learning javascript is freeCodeCamp. One of the challenges at the end of the front-end development section is to build a tribute page with HTML and Bootstrap. Here is the example tribute page. Reproducing this page is easy with basic front-end web knowledge. I decided to give Vue a try as a template engine and reproduce the page. Baby steps.
Simple Example (step 1)
The first thing I tried to do was build a simple example that laid out my the Vue logic that I needed for the tribute page. Here is what I would like this page to do, below is the code I used to make the page work. A working example is on CodePen.
- initialize the page with data from list1
- when the input is changed, change data to the selected list
- render change of data on the page
Template Syntax
Vue uses handlebar like syntax to render data in the DOM. This works within HTML tags, in order to render data within HTML attributes directives like v-bind:href
.
Directives
Directives are used to control the value changes in the DOM. They look like this v-on
, v-for
, v-model
. Directives can be used to bind values to HTML attributes with v-bind
. These allow us to handle eventes (v-on
), conditionally (v-if
, v-show
) render HTML elements or render lists (v-for
).
Dynamic Tribute Page
The HTML skeleton for this app is fairly basic. I haven’t broken the page up into components as I’m currently only trying to get a feel for the template and rendering syntax. The logic is the same as the simple example above:
- initialize the page with data from person 1
- when the input is changed, change data to the selected person
- render change of data on the page
I’ve excluded the data from this example, you can see a working example of the page on CodePen
As in the first example, the logic and Vue code is essentially the same. The template and rendering is a little more complex as I am working with more data and more layout.
Wrap Up
My biggest piece of advice is to read the guide and documentation for Vue. It took me several times reading through it before everything started to click. From there experiment with Vue on CodePen for a while to get the hang of it.