Vue from Scratch
Vue from Scratch
A friendly guide for absolute beginners
About the Book
In this no fluff book, we dive straight in to building apps in Vue.
In chapter 1, we build the smallest possible Vue app, and get to know about:
* How to mount a Vue app
* String interpolation and data in HTML
* Adding a Vue instance and its options object
Once we've learned the very basics of how Vue is put together, we build a simple todo app in Vue 2.6, in chapter 2. Through the building of this app, we learn new concepts and build on the existing ones:
* Using the v-bind directive to connect Vue data to HTML attributes
* Handling button clicks with v-on:click
* Handling input events with v-on:input , v-on:keyup , v-on:keydown
* Handling more than one keypress event
* Preventing default behavior with event modifiers
* Modelling our app’s data
* Using the v-for directive to loop over Vue’s data arrays
* Preventing page reload on the form element
* Adding a toggle button with text and style updates
* Mounting and unmounting HTML elements with v-if and v-else
* Binding a CSS class in HTML to our Vue instance’s data option and showing this CSS class
conditionally
* Utilizing confirm popups in our apps
In Chapter 3, we introduce Vue CLI, and cover the following topics:
* How to install Vue on our machine,
* How to build a new Vue app using Vue CLI,
* How to serve our boilerplate Vue app in the browser,
* We inspected all the files and folders in the boilerplate Vue app that we installed using the
Vue CLI, and we discuss what they do and how they fit together
In Chapter 4, we have a sort of a revision of concepts from Chapters 1 and 2, but this time covered through the lens of working with Vue CLI, including:
* How to add a child component to our project
* How to interpolate string values from the data option of our Vue instance
* How to randomly pick and return string values from a method in the methods option of our
Vue instance, and interpolate that value in our single-file component’s template section
* How to bind a Vue instance’s data as a value of a template’s HTML attribute
* We also go through each file and folder in the starter app and describe why it's there and how it works
In Chapter 5, we learn about single-file components in a Vue app:
* Adding children components
* Revising interpolation (this time, in SFCs)
* Templating with values returned from methods
In Chapter 6, we discuss data flows in a Vue app:
* Sending data from the parent component to a child component
* Sending data from the child component to a parent component
* Emitting events with additional data
* We practice components' communication by building another Vue app
* We cover prop-related issues, such as naming conventions, using props in methods, fixing prop errors, passing props as various data types (prop binding)
In Chapter 7, we integrate a linting tool, ESLint, and a library, Bootstrap Vue, with our Vue CLI-powered Vue apps
* Revision of basic concepts: installing Vue, preparing VS Code to use it, installing the boilerplate Vue.js app with Vue CLI, removing redundant code from the starter app
* Setting up ESLint to work with Vue.js
* Styling our app with BootstrapVue
* Adding Vue Chrome extension
* Restarting our app (dealing with some weird errors)
In Chapter 8, we build the todo app again, this time with Vue CLI. This serves a double purpose:
* We revise all the concepts needed to build a todo app
* This chapter is a practical example on converting a non-Vue CLI app to a Vue CLI SFC Vue app. The insights you'll gain here are very valuable for a new Vue developer
In Chapter 9, another hands-on chapter, we continue working with the app we've built in Chapter 8, but this time we demo how to split a single file component into a component and a sub-component. We show the practical implementation of one-way data flow approach on an app that we're now quite familiar with, which helps us keep focus on understanding how to make our Vue apps more modular.
In Chapter 10, we "back-fill" our knowledge with some basic concepts that we've skipped in earlier chapters.
Table of Contents
-
Chapter 1: The absolute basics
- The smallest possible Vue.js app
- String interpolation in Vue
- Data in HTML
- Adding a Vue instance
- A Vue instance’s options object
- A Vue instance’s options object’s data option
- Other options in the Vue instance’s options object
- Summary
-
Chapter 2: Building a todo app in Vue
- Adding the static HTML
- Adding a Vue instance
- Adding a heading with Vue
- Letting Vue control the input’s placeholder string
- Handling button clicks with Vue
- Handling input events with Vue
- Handling keypress events with Vue
- Handling more than one keypress event with Vue
- Preventing default behavior with event modifiers
- Modelling our todo item data
- Vue’s version of a for loop (in HTML!)
-
Adding ordinal numbers using the
v-for
directive - Adding a new todo entry using two-way data binding
- Emitting input events
- Implementing two-way data binding in our todo app
-
Two-way binding shorthand syntax with
v-model
- Updating the list of todos in our unordered list
-
Preventing page reload on the
form
element - Clearing all todos
- Adding a completed toggle button to each todo
- Using a v-if to mount HTML elements conditionally
- Erasing single todos
- Warn the user with a browser confirm popup
- Clear the input field whenever a user adds a todo
- Let’s review the full code of our todo app
- Summary
-
Chapter 3: Convert a static HTML page to Vue
- Inspecting the source of our customized HTML layout
- Importing Vue and mounting it in the DOM
- Mounting a new instance of Vue
- Adding multiple Vue instances to our HTML layout
- Passing data to the cards section
- Avoiding the repetition with v-for
- Adding a bit more interactivity
- Affecting data in one Vue instance from another Vue instance
- Adding Bootstrap background classes
-
Binding the
class
attribute to a method call - Conclusion
-
Chapter 4: Build a Vue project with Vue CLI
- Installing Vue CLI
- Build a new project quickly with Vue CLI
- Review the structure of our app
-
The
node_modules
folder -
The
public
folder -
The
src
folder - Stand-alone files at the very root of our Vue app
- Conclusion
-
Chapter 5: Child components, data interpolation, and single file components
- Introduction
- 1. Adding children components
-
2. Templating: Interpolating values stored in the
data
option -
3. Templating: Interpolating values returned from the
methods
option - Remember: We can’t interpolate strings inside HTML attributes
- Conclusion
-
Chapter 6: Data flows in a Vue app
-
1. What is a
prop
? - 2. Sending data from the parent component to a child component
- 3. Sending data from the child component to a parent component
- 4. Emitting events with additional data
- 5. Practice: A message-passing app
- 6. Prop names as kebab-case or as lowerCamelCase?
- 7. Using props in methods
- 8. Fixing the “Avoid mutating a prop directly” error
- 9. Giving more information about our props with nested objects
- 10. Passing props as data types other than “string”, and binding props with v-bind
- 11. Making props more dynamic with v-bind and v-for
- 12. Practicing the passing of data with emitted custom events
- 13. Conclusion
- 14. Summary
-
1. What is a
-
Chapter 7: Using Vue CLI with ES Lint and Bootstrap-Vue
-
1. Renaming the
HelloWorld
component to theCaloryCounter
component -
2. Adding and displaying data inside the
CalorieCounter.vue
component - 3. Setting up ESLint to work with Vue.js
- 4. Styling our app with BootstrapVue
- 5. Adding Vue Chrome extension
- 6. Adding a navigation component to our app
- 7. Restarting our app
- Summary
-
1. Renaming the
-
Chapter 8: Building the Todo app again, this time with Vue CLI
- Prepping a brand new Vue app for Bootstrap-Vue
- 3. Add BootstrapVue to the app
- 4. Adding the form-input component
- Adding the button component
- Adding the clear all button
- Adding click events to buttons
- Displaying the todos array
- Adding the method to delete a single todo
- Toggling styles
-
Chapter 9: Splitting a Vue app into sub-components
-
Splitting the
TodoForm.vue
code - Conclusion
-
Splitting the
-
Chapter 10: Other important concepts for Vue.js beginners
- 1. Vue-specific shorthand syntax
-
2. Using the
emits
option - 3. Slots and named slots
- 4. Methods, computed properties, and watchers
-
6. The
v-once
directive -
7. The
v-html
directive -
8. The
v-show
directive - 9. The life-cycle of a Vue component
- 10. A Vue component’s life-cycle hooks
-
11. Accessing DOM nodes using the Vue-specific HTML
ref
attribute - Conclusion
-
Chapter 11: Appendix A, the starter app
- 1. Installing Vue.js
- 2. Preparing VS Code for Vue
- 3. Installing the boilerplate Vue.js app with Vue CLI
- 4. Removing redundant code from our boilerplate Vue.js app
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned$12,307,240writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Personal Finance
Jason AndersonThis textbook provides an in-depth analysis on personal finance that is both practical and straightforward in its approach. It has been written in such a way that the readers can gain knowledge without getting overwhelmed by the technical terms. Suitable for both beginners and advanced learners.
Getting to Know IntelliJ IDEA
Trisha Gee and Helen ScottIf we treat our IDE as a text editor, we are doing ourselves a disservice. Using a combination of tutorials and a questions-and-answers approach, Getting to Know IntelliJ IDEA will help you find ways to use IntelliJ IDEA that enable you to work comfortably and productively as a professional developer.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
Stats One
William FooteMachine Learning Q and AI
Sebastian Raschka, PhDHave you recently completed a machine learning or deep learning course and wondered what to learn next? With 30 questions and answers on key concepts in machine learning and AI, this book provides bite-sized bits of knowledge for your journey to becoming a machine learning expert.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Gradual Modularization for Ruby and Rails
Stephan HagemannGet yourself a new tool to manage your Rails application and your growing engineering organization! Prevent the ball-of-mud (and fix it!). Go for microservices or SOA if it makes sense not just because you don't have any other tool. Do all this through a low-overhead tool: packages. Enable better conversations to make practical changes today.
Top Bundles
- #1
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
1500 QUIZ COMMENTATI (3 libri)
3 Books
Tre libri dei QUIZ MMG Commentati al prezzo di DUE! I QUIZ dei concorsi ufficiali di Medicina Generale relativi agli anni: 2000-2001-2003-2012-2013-2014-2015-2016-2017-2018-2019-2020-2021 +100 inediti Raccolti in unico bundle per aiutarvi nello studio e nella preparazione al concorso. All'interno di ogni libro i quiz sono stati suddivisi per... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #5
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #7
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #9
Development and Deployment of Multiplayer Online Games, Part ARCH. Architecture (Vol. I-III)
3 Books
What's the Big Idea? The idea behind this book is to summarize the body of knowledge that already exists on multiplayer games but is not available in one single place.And quite a fewof the issues discussed within this series (planned as three nine volumes ~300 pages each), while known in the industry, have not been published at all (except for... - #10
Modern C++ Collection
3 Books
Get All about Modern C++C++ Standard Library, including C++20Concurrency with Modern C++, including C++20C++20Each book has about 200 complete code examples. Updates are included. When I update one of the books, you immediately get the updated bundle. You can expect significant updates to each new C++ standard (C++23, C++26, .. ) and also...