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
Do Well. Do Good.
Authors have earned$11,845,077writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
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
The Hitchhiker's Guide to DFIR: Experiences From Beginners and Experts
Barry Grundy, Tristram, John Haynes, ApexPredator, Andrew Rathbun, Kevin Pagano, Victor Heiland, Nisarg Suthar, Guus Beckers, and Jason WilkinsA first-of-its-kind crowdsourced Digital Forensics and Incident Response (DFIR) book by the Digital Forensics Discord Server members to share knowledge!
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.
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.
Maîtriser Apache JMeter
Philippe Mouawad, Bruno Demion (Milamber), and Antonio Gomes RodriguesToute la puissance d'Apache JMeter expliquée par ses commiteurs et utilisateurs experts. De l'intégration continue en passant par le Cloud, vous découvrirez comment intégrer JMeter à vos processus "Agile" et Devops.
If you're looking for the newer english version of this book, go to Master JMeter : From load testing to DevOps
Software Architecture for Developers
Simon BrownA developer-friendly, practical and pragmatic guide to lightweight software architecture, technical leadership and the balance with agility.
Functional Event-Driven Architecture
Gabriel VolpeExplore the event-driven architecture (EDA) in a purely functional way. Learn to design and develop distributed systems that scale. Identify common design patterns in such systems.
Take your functional programming skills to the next level by joining me in developing a distributed system powered by Apache Pulsar and Fs2 streams, all in Scala 3!
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.
Concurrency with Modern C++
Rainer GrimmC++11 is the first C++ standard that deals with concurrency. The story goes on with C++17, C++20, and will continue with C++23.
I'll give you a detailed insight into the current and the upcoming concurrency in C++. This insight includes the theory and a lot of practice.
Thinking with Types
Sandy MaguireThis book aims to be the comprehensive manual for type-level programming. It's about getting you from here to there---from a competent Haskell programmer to one who convinces the compiler to do their work for them.
Biological Modeling
Phillip CompeauIn this ebook, learn why zebras have stripes, why SARS-CoV-2 spread so quickly around the planet, how to train a computer to classify cellular images, and more!
Top Bundles
- #1
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... - #2
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... - #3
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... - #4
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!? - #6
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... - #8
Learn Git, Bash, and Terraform the Hard Way
3 Books
Learn Git, Bash and Terraform using the Hard Way method.These technologies are essential tools in the DevOps armoury. These books walk you through their features and subtleties in a simple, gradual way that reinforces learning rather than baffling you with theory. - #9
Quality Software
11 Books
The Quality Software Bundle is for managers, would-be managers, and any of us who find themselves being managed and confused. This comprehensive bundle covers the entire span of software development approaches, from hacking through waterfall, cascade, prototyping, Iterative enhancement, reusable code, off-the-shelf, to Agile teams. The bundle... - #10
Static Analysis and Automated Refactoring
2 Books
As PHP developers we are living in the "Age of Static Analysis". We can use a tool like PHPStan to learn about potential bugs before we ship our code to production, and we can enforce our team's programming standards using custom PHPStan rules. Recipes for Decoupling by Matthias Noback teaches you in great detail how to do this, while also...