Professional Documents
Culture Documents
Full Chapter Pro Vue Js 2 1St Edition Adam Freeman PDF
Full Chapter Pro Vue Js 2 1St Edition Adam Freeman PDF
https://textbookfull.com/product/pro-react-16-1st-edition-adam-
freeman/
https://textbookfull.com/product/pro-entity-framework-core-2-for-
asp-net-core-mvc-adam-freeman/
https://textbookfull.com/product/pro-angular-6-3rd-edition-adam-
freeman/
https://textbookfull.com/product/pro-angular-16-6th-edition-adam-
freeman/
Essential TypeScript: From Beginner to Pro 1st Edition
Adam Freeman
https://textbookfull.com/product/essential-typescript-from-
beginner-to-pro-1st-edition-adam-freeman/
https://textbookfull.com/product/essential-typescript-4-from-
beginner-to-pro-2nd-edition-adam-freeman/
https://textbookfull.com/product/essential-typescript-4-from-
beginner-to-pro-second-edition-adam-freeman/
https://textbookfull.com/product/pro-angular-9-build-powerful-
and-dynamic-web-apps-adam-freeman/
https://textbookfull.com/product/pro-asp-net-core-mvc-2-develop-
cloud-ready-web-applications-using-microsofts-latest-framework-
asp-net-core-mvc-2-seventh-edition-adam-freeman/
Pro
Vue.js 2
—
Adam Freeman
Pro Vue.js 2
Adam Freeman
Pro Vue.js 2
Adam Freeman
London, UK
ISBN-13 (pbk): 978-1-4842-3804-2 ISBN-13 (electronic): 978-1-4842-3805-9
https://doi.org/10.1007/978-1-4842-3805-9
Library of Congress Control Number: 2018956735
Copyright © 2018 by Adam Freeman
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage
and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or
hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material
contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Joan Murray
Development Editor: Laura Berendson
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC
and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail editorial@apress.com; for reprint, paperback, or audio rights,
please email bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web
page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers
on GitHub via the book’s product page, located at www.apress.com/9781484238042. For more detailed
information, please visit www.apress.com/source-code.
Printed on acid-free paper
Dedicated to my lovely wife, Jacqui Griffyth.
(And also to Peanut.)
Table of Contents
Summary ........................................................................................................................ 28
v
■ TABLE OF CONTENTS
Summary ........................................................................................................................ 51
vi
■ TABLE OF CONTENTS
vii
■ TABLE OF CONTENTS
Summary ........................................................................................................................ 87
■Chapter 5: SportsStore: A Real Application ......................................................... 89
Creating the SportsStore Project .................................................................................... 89
Adding Additional Packages ................................................................................................................. 90
Preparing the RESTful Web Service ...................................................................................................... 92
Starting the Project Tools...................................................................................................................... 95
viii
■ TABLE OF CONTENTS
ix
■ TABLE OF CONTENTS
x
■ TABLE OF CONTENTS
xi
■ TABLE OF CONTENTS
xii
■ TABLE OF CONTENTS
xiii
■ TABLE OF CONTENTS
xiv
■ TABLE OF CONTENTS
xv
■ TABLE OF CONTENTS
xvi
■ TABLE OF CONTENTS
xvii
■ TABLE OF CONTENTS
xviii
■ TABLE OF CONTENTS
xix
About the Author
xxi
About the Technical Reviewer
Fabio Claudio Ferracchiati is a senior consultant and a senior analyst/developer using Microsoft
technologies. He works for BluArancio (www.bluarancio.com). He is a Microsoft Certified Solution
Developer for .NET, a Microsoft Certified Application Developer for .NET, a Microsoft Certified Professional,
and a prolific author and technical reviewer. Over the past ten years, he’s written articles for Italian and
international magazines and coauthored more than ten books on a variety of computer topics.
xxiii
PART I
The best way to get started with Vue.js is to dive in. In this chapter, I take you through a simple development
process to create an application to keep track of to-do items. In Chapters 5–8, I show you how to create
a more complex and realistic application, but for now, a simple example will be enough to demonstrate
how Vue.js applications are created and how the basic features work. Don’t worry if you don’t understand
everything in this chapter—the idea is to get an overall sense of how Vue.js works, and I explain everything in
detail in later chapters.
■ Note If you want a conventional description of Vue.js features, then you can jump to Part 2 of this book,
where I start the process of describing individual features in depth.
Installing Node.js
The tools used for Vue.js development rely on Node.js—also known as Node—which was created in 2009
as a simple and efficient runtime for server-side applications written in JavaScript. Node.js is based on the
JavaScript engine used in the Chrome browser and provides an API for executing JavaScript code outside of
the browser environment.
Node.js has enjoyed success as an application server, but for this book, it is interesting because it has
provided the foundation for a new generation of cross-platform development and build tools. Some smart
design decisions by the Node.js team and the cross-platform support provided by the Chrome JavaScript
runtime have created an opportunity that has been seized upon by enthusiastic tool writers. In short, Node.
js has become essential for web application development.
It is important that you download the same version of Node.js that I use throughout this book. Although
Node.js is relatively stable, there are still breaking API changes from time to time that may stop the examples
I include in the chapters from working.
The version I have used is 8.11.2, which is the current Long-Term Support release at the time of writing.
There may be a later version available by the time you read this, but you should stick to the 8.11.2 release
for the examples in this book. A complete set of 8.11.2 releases, with installers for Windows and macOS and
binary packages for other platforms, is available at https://nodejs.org/dist/v8.11.2.
When you install Node.js, make sure you select the option to add the Node.js executables to the path.
When the installation is complete, run command shown in Listing 1-1.
node -v
If the installation has gone as it should, then you will see the following version number displayed:
v8.11.2
The Node.js installer includes the Node Package Manager (NPM), which is used to manage the
packages in a project. Run the command shown in Listing 1-2 to ensure that NPM is working.
npm -v
If everything is working as it should, then you will see the following version number:
5.6.0
■ Note As I write this, the @vue/cli package has been released in beta. There may be small changes made
before the final release, but the core features should remain the same. For details of any breaking changes,
check the errata for this book, available at https://github.com/Apress/pro-vue-js-2.
To install @vue/cli, open a new command prompt and run the command shown in Listing 1-3. If you
are using Linux or macOS, you may need to use sudo.
4
CHAPTER 1 ■ YOUR FIRST VUE.JS APPLICATION
Installing Git
The Git revision control tool is required to manage some of the packages required for Vue.js development.
If you are using Windows or macOS, then download and run the installer from https://git-scm.com/
downloads. (On macOS, you may have to change your security settings to open the installer, which has not
been signed by the developers.)
Git is already included in most Linux distributions. If you want to install the latest version, then consult
the installation instructions for your distribution at https://git-scm.com/download/linux. As an example,
for Ubuntu, which is the Linux distribution I use, I used the command shown in Listing 1-4.
Once you have completed the installation, open a new command prompt and run the command shown
in Listing 1-5 to check that Git is installed and available.
git --version
This command prints out the version of the Git package that has been installed. At the time of writing,
the latest version of Git for Windows and Linux is 2.17, and the latest version of Git for macOS is 2.16.3.
Installing an Editor
Vue.js development can be done with any programmer’s editor, from which there is an endless number to
choose. Some editors have enhanced support for working with Vue.js, including highlighting keywords and
expressions. If you don’t already have a preferred editor for web application development, then Table 1-1
describes some popular options for you to consider. I don’t rely on any specific editor for this book, and you
should use whichever editor you are comfortable working with.
Name Description
Sublime Text Sublime Text is a commercial cross-platform editor that has packages to support most
programming languages, frameworks, and platforms. See www.sublimetext.com for
details.
Atom Atom is a free, open source, cross-platform editor that has a particular emphasis on
customization and extensibility. See atom.io for details.
Brackets Brackets is a free open source editor developed by Adobe. See brackets.io for
details.
Visual Studio Code Visual Studio Code is a free, open source, cross-platform editor from Microsoft, with
an emphasis on extensibility. See code.visualstudio.com for details.
Visual Studio Visual Studio is Microsoft’s flagship developer tool. There are free and commercial
editions available, and it comes with a wide range of additional tools that integrate
into the Microsoft ecosystem.
5
CHAPTER 1 ■ YOUR FIRST VUE.JS APPLICATION
Installing a Browser
The final choice to make is the browser that you will use to check your work during development. All the
current-generation browsers have good developer support and work well with Vue.js, but there is a useful
extension for Chrome and Firefox called vue-devtools that provides insights into the state of a Vue.js
application and that is especially useful in complex projects. See https://github.com/vuejs/vue-devtools
for details of installing the extension, which I use in later chapters. I used Google Chrome throughout this
book, and this is the browser I recommend you use to follow the examples.
The vue command was installed as part of the @vue/cli package in Listing 1-3, and the command in
Listing 1-6 creates a new project called todo, which will be created in a folder of the same name. The project
will be created, and all of the packages required for Vue.js development will be downloaded and installed,
which can take a while because a large number of packages are required even for a simple project.
6
CHAPTER 1 ■ YOUR FIRST VUE.JS APPLICATION
The layout of the project can be daunting, but by the end of the book you will know what the different
files and folders are for and how they are used. In Table 1-2, I have briefly described the files that are
important in this chapter. I describe the structure of Vue.js projects in detail in Chapter 10.
Name Description
public/index.html This is the HTML file that is loaded by the browser. It has an element in which
the application is displayed and a script element that loads the application
files.
src/main.js This is the JavaScript file that is responsible for configuring the Vue.js
application. It is also used to register any third-party packages that the
application relies on, which you will see demonstrated in later chapters.
src/App.vue This is the Vue.js component, which contains the HTML content that will be
displayed to the user, the JavaScript code required by the HTML, and the CSS
that styles the elements. Components are the main building blocks in a Vue.js
application, and you will see them used throughout this book.
src/assets/logo.png The assets folder is used to store static content, such as images. In a new
project, it contains a file called logo.png, which is an image of the Vue.js logo.
7
CHAPTER 1 ■ YOUR FIRST VUE.JS APPLICATION
cd todo
npm run serve
There is an initial preparation process while the development tools start, which can take a moment to
complete. Don’t be put off by the amount of time the preparation takes because this process is required only
when you start a development session.
When the startup process is complete, you will see a message like this one, which confirms that the
application is running and tells you which HTTP port to connect to:
The default port is 8080 although a different port will be selected if 8080 is not available. Open a new
browser window and navigate to http://localhost:8080 (or the URL specified if a different port has been
selected), and you will see the placeholder content shown in Figure 1-2. (The placeholder content changes
as new versions of the development tools are released, so don’t worry if you don’t see precisely the same
content.)
8
CHAPTER 1 ■ YOUR FIRST VUE.JS APPLICATION
<template>
<div id="app">
<img src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App" />
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
name: 'app',
components: {
HelloWorld
}
}
</script>
<style>
9
Another random document with
no related content on Scribd:
donne-t-elle pas à l’esprit une sorte d’apaisement bienfaisant, cette
sérénité de l’aéronaute ou de l’aviateur qui vogue dans l’espace ?
Peut-être cette influence d’une vérité neuve s’exerce-t-elle en ce
moment même sur nos cerveaux ? Peut-être modifie-t-elle le sens
de nos élans, de nos aspirations ? Mais la métamorphose est trop
fraîche, trop actuelle, pour que nous en prenions nettement
conscience.
La connaissance de l’avenir.
L’héritage du passé.
La vie en souplesse.