Download Full Learning Vue Maya Shavin PDF All Chapters

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Get ebook downloads in full at ebookmeta.

com

Learning Vue Maya Shavin

https://ebookmeta.com/product/learning-vue-maya-shavin/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Learning Vue: Core Concepts and Practical Patterns for


Reusable, Composable, Scalable User Interfaces 1st Edition
Maya Shavin
https://ebookmeta.com/product/learning-vue-core-concepts-and-
practical-patterns-for-reusable-composable-scalable-user-
interfaces-1st-edition-maya-shavin/
ebookmeta.com

Vue js A comprehensive beginner s guide to Vue js 1st


Edition Alexander Aronowitz Rufus Stewart

https://ebookmeta.com/product/vue-js-a-comprehensive-beginner-s-guide-
to-vue-js-1st-edition-alexander-aronowitz-rufus-stewart/

ebookmeta.com

Vue js A comprehensive beginner s guide to Vue js 1st


Edition Alexander Aronowitz Rufus Stewart

https://ebookmeta.com/product/vue-js-a-comprehensive-beginner-s-guide-
to-vue-js-1st-edition-alexander-aronowitz-rufus-stewart-2/

ebookmeta.com

Spatial Readings and Linguistic Landscapes 1st Edition


Alina Bako

https://ebookmeta.com/product/spatial-readings-and-linguistic-
landscapes-1st-edition-alina-bako/

ebookmeta.com
Needle in a Timestack Jerry Ebooks Version Robert
Silverberg

https://ebookmeta.com/product/needle-in-a-timestack-jerry-ebooks-
version-robert-silverberg/

ebookmeta.com

Spectral Invariants with Bulk Quasi Morphisms and


Lagrangian Floer Theory 1st Edition Kenji Fukaya

https://ebookmeta.com/product/spectral-invariants-with-bulk-quasi-
morphisms-and-lagrangian-floer-theory-1st-edition-kenji-fukaya/

ebookmeta.com

Routledge Handbook of Critical Studies in Whiteness 1st


Edition Taylor & Francis Group

https://ebookmeta.com/product/routledge-handbook-of-critical-studies-
in-whiteness-1st-edition-taylor-francis-group/

ebookmeta.com

Claimed For Her 3 1st Edition Alexa Riley

https://ebookmeta.com/product/claimed-for-her-3-1st-edition-alexa-
riley/

ebookmeta.com

Chemistry: The Molecular Nature of Matter and Change Third


Canadian Edition Martin Stuart Silberberg

https://ebookmeta.com/product/chemistry-the-molecular-nature-of-
matter-and-change-third-canadian-edition-martin-stuart-silberberg/

ebookmeta.com
Beginning Azure Cognitive Services: Data-Driven Decision
Making Through Artificial Intelligence 1st Edition Alicia
Moniz
https://ebookmeta.com/product/beginning-azure-cognitive-services-data-
driven-decision-making-through-artificial-intelligence-1st-edition-
alicia-moniz/
ebookmeta.com
Learning Vue
Core Concepts and Practical Patterns for Reusable,
Composable, and Scalable User Interfaces

Maya Shavin
Learning Vue
by Maya Shavin Copyright © 2024 Maya Shavin. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North,
Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales
promotional use. Online editions are also available for most titles
(http://oreilly.com). For more information, contact our
corporate/institutional sales department: 800-998-9938 or
[email protected].

Acquisitions Editor: Amanda Quinn

Development Editor: Michele Cronin

Production Editor: Ashley Stussy

Copyeditor: Piper Editorial Consulting, LLC

Proofreader: Liz Wheeler

Indexer: Potomac Indexing, LLC

Interior Designer: David Futato

Cover Designer: Karen Montgomery

Illustrator: Kate Dullea

December 2023: First Edition


Revision History for the First Edition
2023-12-01: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781492098829 for release
details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
Learning Vue, the cover image, and related trade dress are trademarks of
O’Reilly Media, Inc.
The views expressed in this work are those of the author and do not
represent the publisher’s views. While the publisher and the author have
used good faith efforts to ensure that the information and instructions
contained in this work are accurate, the publisher and the author disclaim all
responsibility for errors or omissions, including without limitation
responsibility for damages resulting from the use of or reliance on this
work. Use of the information and instructions contained in this work is at
your own risk. If any code samples or other technology this work contains
or describes is subject to open source licenses or the intellectual property
rights of others, it is your responsibility to ensure that your use thereof
complies with such licenses and/or rights.
978-1-492-09882-9
[LSI]
Preface

The JavaScript framework plays a significant role in modern web frontend


development. When developing web projects, companies choose a
framework for various reasons, including the quality of the final product,
the cost of development, coding standard, and ease of development. Hence,
learning to work with a JavaScript framework, such as Vue, is essential for
any modern web developer (or frontend developer or full stack developer).
This book is for programmers who want to learn and develop Web
applications using Vue library, in JavaScript and TypeScript, from end to
end. It focuses solely on how Vue and its ecosystem can help you build
scalable and interactive web applications in the most straightforward and
comfortable direction. While covering the basics, we will also get into Vue
Router and Pinia for state management, testing, animation, deployment, and
server-side rendering, making sure you are ready to move on and start
developing complex Vue projects right away.
It’s OK if you are not familiar with Vue or the concept of Virtual DOM.
This book doesn’t assume any prior knowledge of Vue or any similar
framework. I will introduce and guide you through all Vue’s basics from
scratch. I will also walk you through the Virtual DOM concept and
reactivity system in Vue in Chapter 2, as the foundation for the rest of the
book.
This book doesn’t require you to know TypeScript, though you will be
better prepared if you are familiar with TypeScript basics. You will also be
better prepared for the contents of the book if you have prior basic
knowledge of HTML, CSS, and JavaScript. A solid foundation of these
three is always crucial before diving to any web (or frontend) Javascript
framework.

Conventions Used in This Book


The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file
extensions.

Constant width
Used for program listings, as well as within paragraphs to refer to
program elements such as variable or function names, databases, data
types, environment variables, statements, and keywords.

Constant width bold


Shows commands or other text that should be typed literally by the user.

Constant width italic


Shows text that should be replaced with user-supplied values or by
values determined by context.

TIP
This element signifies a tip or suggestion.

NOTE
This element signifies a general note.

WARNING
This element indicates a warning or caution.
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for
download at https://github.com/mayashavin/learning-vue-app.
If you have a technical question or a problem using the code examples,
please send email to [email protected].
This book is here to help you get your job done. In general, if example code
is offered with this book, you may use it in your programs and
documentation. You do not need to contact us for permission unless you’re
reproducing a significant portion of the code. For example, writing a
program that uses several chunks of code from this book does not require
permission. Selling or distributing examples from O’Reilly books does
require permission. Answering a question by citing this book and quoting
example code does not require permission. Incorporating a significant
amount of example code from this book into your product’s documentation
does require permission.
We appreciate, but generally do not require, attribution. An attribution
usually includes the title, author, publisher, and ISBN. For example:
“Learning Vue by Maya Shavin (O’Reilly). Copyright 2024 Maya Shavin,
978-1-492-09882-9.”
If you feel your use of code examples falls outside fair use or the
permission given above, feel free to contact us at [email protected].

O’Reilly Online Learning

NOTE
For more than 40 years, O’Reilly Media has provided technology and business training,
knowledge, and insight to help companies succeed.
Our unique network of experts and innovators share their knowledge and
expertise through books, articles, and our online learning platform.
O’Reilly’s online learning platform gives you on-demand access to live
training courses, in-depth learning paths, interactive coding environments,
and a vast collection of text and video from O’Reilly and 200+ other
publishers. For more information, visit http://oreilly.com.

How to Contact Us
Please address comments and questions concerning this book to the
publisher:

O’Reilly Media, Inc.

1005 Gravenstein Highway North

Sebastopol, CA 95472

800-889-8969 (in the United States or Canada)

707-829-7019 (international or local)

707-829-0104 (fax)

[email protected]

https://www.oreilly.com/about/contact.html

We have a web page for this book, where we list errata, examples, and any
additional information. You can access this page at https://oreil.ly/learning-
vue-1e.
For news and information about our books and courses, visit
https://oreilly.com.
Find us on LinkedIn: https://linkedin.com/company/oreilly-media
Follow us on Twitter: https://twitter.com/oreillymedia
Watch us on YouTube: https://youtube.com/oreillymedia

Acknowledgments
As I embarked on the journey of writing this book, my family was
navigating a tumultuous period, full of highs and lows. Despite enjoying
every moment, writing this book required a lot of time, effort, and
dedication, and I wouldn’t be able to commit to it without the support from
my family, particularly my husband, Natan. His encouragement, belief in
my programming skills, humor about frontend development, parenting our
children during my work travels, lending an ear to my daily grievances, and
helping me balance work with personal life have been invaluable. Without
Natan, I would not be where I am today.
Just as quality code demands thorough review, this book’s excellence owes
much to critical technical insights and encouragement from Jakub
Andrzejewski, Chris Fritz, Lipi Patnaik, Edward Wong, and Vishwesh Ravi
Shrimali. Your valuable feedback has been pivotal in sharpening my focus
and elevating the quality of this work.
My heartfelt appreciation goes to my O’Reilly team: Zan McQuade and
Amanda Quinn, for guiding me through the acquisition process of Learning
Vue, and to my exceptional editor, Michele Cronin. Michele, your insightful
feedback, professionalism, and empathy, particularly during the challenging
final stages of the book, were extraordinary. The production editing skills of
Ashley Stussy and the copyediting expertise of Beth Richards were crucial
in elevating my manuscript to production quality. This book wouldn’t have
materialized as envisioned without your collective efforts.
I extend a special thank you to the Vue core team for developing such a
great framework and ecosystem, and to the Vue community members and
friends for their support and inspiration. The knowledge and insights I
gained from you are immeasurable and continue to enrich me daily.
Finally, my profound gratitude to you, the readers. Choosing this book from
the plethora of resources available, including countless videos and tutorials,
demonstrates a trust in my work that I deeply appreciate. I hope Learning
Vue serves as a valuable tool in your journey, whether you aspire to be a
web, frontend, or full-stack developer.
Thank you, from the bottom of my heart. And remember, in the world of
web development, always “react with a Vue.”
Chapter 1. Welcome to the
Vue.js World!

Initially released in 2014, Vue.js has experienced rapid adoption, especially


in 2018. Vue is a popular framework within the developer community,
thanks to its ease of use and flexibility. If you are looking for a great tool to
build and ship excellent performant web applications to end users, Vue.js is
the answer.
This chapter highlights the core concepts of Vue.js and walks you through
the tools you need for your Vue.js development environment. It also
explores helpful tools that make your Vue.js development process more
manageable. By the end of the chapter, you will have a working
environment with a simple Vue.js application ready to start your journey in
learning Vue.js.

What Is Vue.js?
Vue.js, or Vue, means view in French; it is a JavaScript engine for building
progressive, composable, and reactive user interfaces (UI) in frontend
applications.

NOTE
We will use the term Vue to indicate Vue.js from this point on.

Vue is written on top of JavaScript and offers an organized mechanism to


structure and build a web application. It also acts as the trans-compiler
(transpiler) that compiles and translates Vue code (as a Single File
Component, which we will discuss further in “Vue Single File Component
Structure”) into equivalent HTML, CSS, and JavaScript code in build time
before deploying. In a standalone mode (with a generated script file), the
Vue engine performs the code translation at run-time instead.
Vue follows the MVVM (Model–View–ViewModel) pattern. Unlike MVC
(Model–View–Controller),1 the ViewModel is the binder that binds data
between the View and Model. Allowing direct communication for the view
and model progressively enables the component’s reactivity.
In short, Vue was created to focus only on the View layer but is
incrementally adaptable to integrate with other external libraries for more
complex usage.
Since Vue focuses solely on the View layer, it empowers the development
of single-page applications (SPAs). SPAs can move quickly and fluidly
while communicating data continuously with the backend.
The official website for Vue includes API documentation, installation, and
primary use cases for reference.

The Benefits of Vue in Modern Web


Development
A significant advantage of Vue is its well-written, easy-to-understand
documentation. In addition, the ecosystem and supporting community built
around Vue, such as Vue Router, Vuex, and Pinia, helps developers set up
and run their projects with minimum effort.
Vue APIs are straightforward and familiar to anyone who has worked with
AngularJS or jQuery before. Its powerful template syntax minimizes the
learning effort required and makes it easier to work with data or listen to
Document Object Model (DOM) events in your application.
Another significant benefit Vue offers is its size. The size of a framework is
a substantial aspect of the application’s performance, especially the initial
loading time on delivery. At the time of writing, Vue stands as the fastest
and most lightweight framework (~10kB in size). This advantage results in
less time-consuming downloading and better run-time performance from a
browser perspective.
With the release of Vue 3, the built-in support for TypeScript now offers
developers the benefit of typing in types and making their codebase more
readable, organized, and maintainable in the long term.

Installing Node.js
Working with Vue requires setting up the development ecosystem and prior
coding knowledge to keep up with the learning process. Node.js and NPM
(or Yarn) are necessary development tools to install before you start
working on any application.
Node.js (or Node) is an open source JavaScript server environment built on
Chrome’s V8 JavaScript run-time engine. Node allows developers to code
and run JavaScript applications locally or in a hosted server, outside a
browser.

NOTE
Chromium-based browsers like Chrome and Edge also use the V8 engine to interpret
JavaScript code into efficient low-level computer code and execute it.

Node is cross-platform supported and easy to install. If you are not sure you
installed Node, open your terminal (or command prompt in Windows) and
run the following command:

node -v

The output should be a Node version or “Command not found” if Node is


not installed.
If you haven’t installed Node, or your Node version is lower than 12.2.0,
please visit the Node project website and download the installer for the
latest version based on your operation system (Figure 1-1).
Once the download finishes, click on the installer and follow the
instructions to set it up.
When installing Node, besides the node command, you also have the npm
command added to the command-line tool. If you type the node -v
command, you should see the installed version number displayed.

Figure 1-1. Latest version for download in Node’s official website

NPM
The Node Package Manager (NPM) is the default package manager for
Node. It will be installed together with Node.js by default. It lets developers
download and install other remote Node packages with ease. Vue and other
frontend frameworks are examples of helpful Node packages.
NPM is a powerful tool for developing complex JavaScript applications,
with the ability to create and run task scripts (to start a local development
server, for instance) and automatically download project package
dependencies.
Similar to the Node version check, you can perform an NPM version check
through the npm command:

npm -v

To update your NPM version, use the following command:

npm install npm@latest -g

With parameter @latest, your current NPM tool automatically updates its
version to the latest version. You can run npm -v again to ensure it is
updated correctly. You can also replace the latest word to target any
specific NPM version (in the format xx.x.x). Additionally, you need to
indicate the installation at the global scope with the -g flag for the npm
command to be available everywhere on your local machine. For example,
if you run the command npm install [email protected] -g, the tool will target
the NPM package version 6.13.4 for installing and updating.

NPM VERSION FOR THIS BOOK


I recommend installing NPM version 7.x to be able to follow all the NPM code
examples in this book.

A Node project depends on a collection of Node packages2 (or


dependencies) to be up and running. In the package.json file within the
project directory, you can find these installed packages. This package.json
file also describes the project, including the name, author(s), and other
scripting commands applied to the project exclusively.
Other documents randomly have
different content
THE BRIDGE OF
MIEN CHUH SZE CHUAN.

When a rich man or a company of rich men wish to benefit their


province, it is quite a common thing for them to let their generosity
take the form of the building of a bridge. This bridge was so built. It is
a most beautiful structure, both in form and colour. The roof is of
green tiles, the inside being lined with crimson lacquer, deeply
incised in gold with the names of the donors.
THE BRIDGE OF
MIEN CHUH SZE CHUAN
A SIMPLE
COUNTRY BRIDGE.

The kind of bridge found on a secondary road in Sze Chuan,


constructed of wood roofed in with tiles, after the manner of
Switzerland, to protect it from the weather.
A SIMPLE
COUNTRY BRIDGE
A DRAGON BRIDGE.

Quite a common form of stone bridge, in which every pier is


surmounted by a dragon, the national emblem.
A DRAGON BRIDGE
THE ZIG-ZAG BRIDGE
OF SHANGHAI.

Its name indicates its peculiar character. It makes nine zig-zags


across the water to the most celebrated tea house in Shanghai, and,
perhaps, the most fashionable tea house in China. It is the resort of
mandarins and people of the upper classes. Women are never seen
at the tea houses. They are patronised by men only. Women,
indeed, are very little seen in public at all. The absence of the female
element is a marked feature in Chinese life.
THE ZIG-ZAG BRIDGE
OF SHANGHAI
THE GARDEN OF THE
GUILD OF BENEVOLENCE, CHUNG
KING.

China is the country of guilds. All workmen and traders have their
guilds. To this rule there are but two exceptions—the water-carriers
and the trackers (men who drag the boats up the rapids); these
alone have no trade organisation. These guilds, or trade unions, are
as complete and as effective for good or harm as anything we know
in this country. They watch most jealously the interests of their craft.
But the guild enters into the life of the people at every turn. The
charities of the Empire, which are numerous, are conducted by
guilds. There is, perhaps, little personal charity and benevolence; it
is safer to leave these to the guilds. But there is scarcely a town of
any size that has not its Guild of Benevolence. Soup kitchens,
clothing for the living, coffins and burial for the dead, hospitals, free
dispensaries, orphan and foundling homes, life-boats, and many
other charities are the outcome of these Guilds of Benevolence.
THE GARDEN OF THE
GUILD OF BENEVOLENCE,
CHUNG KING
A BURIAL CHARITY.

A cemetery, with temple attached, for the burial, with all sacred
rites, of strangers who may have died friendless. To a Chinaman the
most important event in his history is his burial. We can have no idea
of what decent burial means to him. He is thinking of it and arranging
for it all his life, and it is not to be wondered at that so large a part of
the operation of Chinese charity should connect itself with funerals.
To be suitably buried is the great hope and aim of every Chinaman.
This Cemetery, with its funeral rites, is one of the operations of a
Guild of Benevolence.
A BURIAL CHARITY
A BABY TOWER,
FOOCHOW.

When a baby dies, and the parents are too poor to give it a decent
burial, they drop its poor little body into one of the openings in this
tower. A Guild of Benevolence charges itself with the task of clearing
out the tower every two or three days, burying the bodies with all
religious rites and ceremony.

You might also like