I’m Zaydek and I’m newish to web development. I come from a background in graphic design and programming, so picking up the frontend has been fascinating for me.
The web is like the offspring of a graphic designer and programmer — it’s both visual and programmatic. So today, I’m going to introduce you to Vue.js and component-based web design — that is, modern web development. I’ll take you from a newbie web developer to an all-powerful, all-knowing web developer seer!
How can you make such claims, sir?
— Fancy you
Well, the thing is, most people learned how to Internet before we (as a whole) understood how to Internet! Including me! 😅 Which, to be honest, is probably why I refused to learn web development for the longest time. It just felt so broken!
But times they are a-changin’ and web development has never been more accessible or streamlined. So it is my great honor, and privilege, to introduce you to how to Internet in 2018, and perhaps even beyond!
So why Vue? It’s a great and fair question you should be asking. Some people protest and scorn the idea of using any framework, and I think this is a dangerous idea. I do, however, suggest that for whatever tool it is that you use, to be very deliberate and thoughtful in why you’re using it.
I picked up Vue because I want to use newer tools that are not too mainstream. I wanted them to have learned from tools that have come before them (or in other words, are not too trailblazing). They should have best-in-class documentation, and have a critical mass of users.
Since Vue, in the last weeks, surpassed React is stars in GitHub, that is evidence to me that Vue has a critical mass. 😀
Furthermore, Vue is an extraordinary open-source project, is publicly-funded, and has a great developer-experience! Like user-experience but for developers. This has the wonderful consequence that the common developer can now create interactive websites intuitively. And Vue builds on one of the most successful ideas from the Angular-React wars which is the Virtual DOM. So let’s talk about that now.
— Internet You
Virtual DOM, yo. LOL sorry. So let’s back up — DOM is short for document-object-model. I think of the DOM as a paradigm for how we think about text as data structures to compose what we call web pages. And a virtual DOM is a clever abstraction for dealing with the text that goes between the elements, like
<p>hello, world!</p>. In an idiomatic Vue-based website it’s something like
— Innocent You
Sorry for blabbering! It’s hard for me not to talk about this at length, partly because it’s so exciting. And also partly because of the gamut of possibilities that present themselves when a sole developer can be responsible for building beautiful and interactive web apps/businesses. Businesses you say? Yes — Follow me on Twitter and I’ll be be sure to follow up! 🖖
Without further ado, here’s the HTML for the website:
Psst… the full code is available in the ninth screencast.
Feeling shocked? The thing is, let’s think about the inherent complexity of the website I’ve shown you. It’s really just a box with two cells, one with an emoji and one with text, repeating 12 times. Yes, there’s some padding, there are some gradients, but the fundamental design is unchanged. So what if the code’s complexity was proportional to the design’s complexity?
Here I’ve applied a CSS debugger to disambiguate the design, but this only goes as far as the CSS is concerned. What’s more important here, the real significance of Vue, is how we can think about our website in terms of data and not in terms of HTML elements.
So look again at those images. If we think about our website purely in terms of data, how much data is there?
Allow me to now share the underlying data structure used:
The following sentence is possibly the most important: Vue frees us to think about our website in terms of data, separate from the HTML; this is a revolution for how we can build for the web!
To be explicit, what I’m showing you is an array of anonymous objects each with two keys:
color. Now that we can represent the website in terms of data, we just iterate over the data using Vue’s
v-for and a custom component.
Components — yes! Second to separating the data from the HTML, one of the coolest things Vue offers is component-based design. Components can help us abstract blocks of HTML/CSS/JS into a reusable unit: a component.
A quick note: I decided it would be best to first learn how to use Vue without a build-process, meaning I’m not making use of single-file-components. But I am making use of components via
<swatch> element I demo’d earlier in the source code? That’s a custom component I engineered using Vue to abstract the element from the implementation. This is a significant concept, because it means we can start to think more functionally than imperatively.
What’s the difference? Functional design cares about the result, whereas imperative design cares about the result and the implementation. Designing a component is an imperative process, whereas using one is a functional. 🧠
This is the implementation for the
swatch element shown earlier. How it works is that Vue scans the DOM for instances of
swatch and replaces it with the quotes HTML inside of the component’s
template value. This means we can do major refactoring to better understand our website in terms of concepts, rather than being worried about how something ought to be engineered all the time.
I know this might be a lot to take in, especially for something appearing so harmless as a 🎨 color picker. But what I’ve shown you is (besides the CSS) 90% of the codebase. There are at least a few helper functions I’m omitting, but the point is that the techniques and ideologies discussed add up to a lot more than a cute web app. It means that a sole individual can create beautiful and functional web-based products and services for others.
I’m also suggesting that Vue is a lot more than a framework. If paired with the right backend language (let’s hear it for Go!), learning and using Vue adds up to a lot more. Idiomatic Vue can also teach what modern software development means, and how to access the billions(!) of us that are now connected, without the same technical barriers that come with app development.
Vue and Laravel To-Do App - Restful API Project
Build Web Apps with Vue JS 2 & Firebase
Vue JS 2 Course for Students with ZERO ES6 foundation
Building a TodoMVC Application in Vue, React and Angular