Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learning Vue.js 2
Learning Vue.js 2

Learning Vue.js 2: Learn how to build amazing reactive web applications easily with Vue.js

eBook
₹2919.99
Paperback
₹3649.99
Subscription
Free Trial
Renews at ₹400p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning Vue.js 2

Chapter 2. Fundamentals – Installing and Using

In the previous chapter, we gained some familiarity with Vue.js. We were able to use it in two different applications that we created from scratch. We learned how to integrate Vue.js into an already existing project. We were able to see Vue's reactive data binding in action.

Now, you are probably asking yourself: how does it work? What does it do to achieve this behavior of fast UI changes when the data model is changed? Probably, you decided to use Vue.js in your project and are now wondering whether it follows some architectural pattern or paradigm so that you should adopt it in your project. In this chapter, we will explore the key concepts of the Vue.js framework to understand all its behind the scenes features. Also in this chapter, we will analyze all the possible ways of installing Vue.js. We will also create a skeleton for our applications, which we will develop and enhance through the next chapters. We will also learn ways of debugging...

MVVM architectural pattern


Do you remember how we were creating the Vue instance in the first chapter? We were instantiating it calling new Vue({...}). You also remember that in the options, we were passing the element on the page where this Vue instance should be bound and the data object that contained the properties we wanted to bind to our View. The data object is our Model and the DOM element where the Vue instance is bound is our View:

Classic View-Model representation where the Vue instance binds one to another

In the meantime, our Vue instance is something that helps to bind our Model to the View and vice versa. Our application thus follows Model-View-ViewModel (MVVM) pattern, where the Vue instance is a ViewModel:

The simplified diagram of the Model-View-ViewModel pattern

Our Model contains data and some business logic, and our View is responsible for its representation. ViewModel handles data binding, ensuring that the data changed in the Model is immediately affecting the View...

DefineProperty, getters, and setters


So, what happens with the data once passed to the Vue instance? What are these transformations that Vue applies to it so that it becomes so automatically bound to the View layer?

Let's analyze what would we do if we had, let's say, a string, and every time it changes we would like to apply some transformations to some DOM element. How would we apply the string-changing listener function? To what would we attach it? There is no such thing as var stringVar='hello';stringVar.onChange(doSomething) .

So we would probably wrap the string's value setting and getting in some sort of function that would do something, for example, updating the DOM each time the string was updated. How would you implement it? While you're thinking about it, I'll prepare a quick demo of something interesting.

Open the developer tools on your shopping list application. Let's code a little bit. Create an obj variable and another text variable:

var obj = {}; 
var text = ''; 

Let...

Comparing with other frameworks


When you try a new tool, you want to know how it compares with other tools or frameworks. You can find a deep analysis in this regard on the official page of Vue.js: http://vuejs.org/guide/comparison.html . I will just point to some topics that I find important regarding the mostly used frameworks.

React

React and Vue are really similar. They both use virtual DOM, have reusable components, and are about reactive data. It is worth mentioning, however, that Vue only uses virtual DOM starting from its second major version. Prior to Vue 2.0, it used real DOM. The Vue 2.0 release not only became more performant than Vue 1.0 but it also became more performant than React ( http://vuejs.org/guide/comparison.html#Performance-Profiles ).

The most significant difference is probably the way you create your components in both frameworks. You might already know that in React, everything is JavaScript. Developing everything, even templates, in JavaScript, can actually be good...

Vue.js fundamentals


Before putting our hands into the code and starting to enhance our applications with components, plugins, mixins, templates, and other things, let's overview the main Vue features. Let's analyze what are reusable components and how the application state can be managed, and also talk about plugins, filters, and mixins. In this section, we will have just a slight overview of these features. We will learn them deeply in the next chapters.

Reusable components

Now that you know not only what data binding in Vue.js is and how to use it, but also how it works, it is time to introduce another powerful Vue.js feature. Components created with Vue.js can be used and reused in the application as bricks you build your house of. Each component has its own scope of styles and bindings, being completely isolated from the other components.

The component creation syntax is very similar to the Vue instance creation that we already know, and you should only use Vue.extend instead of just Vue...

Installing, using, and debugging a Vue.js application


In this section, we will analyze all the possible ways of installing Vue.js. We will also create a skeleton for our applications that we will develop and enhance through the next chapters. We will also learn the ways of debugging and testing our applications.

Installing Vue.js

There are a number of ways to install Vue.js. Starting from classic, including the downloaded script into HTML within the <script> tags, using tools like bower, npm, or Vue's command-line interface (vue-cli), to bootstrap the whole application.

Let's have a look at all these methods and choose our favorite. In all these examples, we will just show a header on a page saying Learning Vue.js.

Standalone

Download the vue.js file. There are two versions, minified and developer version. The development version is at https://vuejs.org/js/vue.js . The minified version is at https://vuejs.org/js/vue.min.js .

Tip

If you are developing, make sure you use the development non...

Debugging your Vue application


You can debug your Vue application the same way you debug any other web application. Use your developer tools (firebug), breakpoints, debugger statements, and so on. If you want to dive deep inside the Chrome debugging tools, check Chrome's documentation at https://developer.chrome.com/devtools .

Vue also provides Vue.js devtools, so it gets easier to debug Vue applications. You can download and install it from the Chrome web store at https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd .

Unfortunately, it doesn't work with locally opened files, so use some simple HTTP server in order to serve our examples as a web page (for example, https://www.npmjs.com/package/http-server ).

After installing it, open, for example, our shopping list application. Open developer tools. You will see the Vue tab has automatically appeared:

Vue devtools

In our case, we only have one component—<Root>. As you can imagine, once we start...

Scaffolding our applications


Do you remember the two applications that we started to work on in the first chapter, the shopping list application and the Pomodoro one? In this section, we will scaffold these applications using the vue-cli tool in order for them to be ready to contain reusable components, be tested, and be deployed. Once we bootstrap these applications, we will work on them until the end of this book. So let's do it carefully and with lots of love!

Scaffolding the shopping list application

We will scaffold the shopping list application using vue-cli Webpack configuration.

Tip

In case you have ignored all previous practical exercises related to vue-cli, do not forget to install it before proceeding to the next steps: npm install -g vue-cli

If you already have vue-cli installed, go to the directory where you want to bootstrap the application and run the following:

vue init webpack shopping-list

Answer yes to all the questions (just click enter) and voilà! You have the application...

Exercise


Implement our Pomodoro application as a Chrome app! You just need to use it with a CSP-compliant version of Vue.js and add a manifest.json file.

Summary


In this chapter, we have analyzed the behind-the-scenes of Vue.js. You learned how data reactivity is achieved. You saw how Vue.js leverages Object.defineProperty getters and setters to propagate changes in the data. You saw an overview of the key Vue.js concepts, such as reusable components, plugins system, and state management with Vuex. We have bootstrapped the applications that we will develop during the next chapters.

In the next chapter, we will have a deeper look into the Vue's components system. We will use components in our applications.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn how to propagate DOM changes across the website without writing extensive jQuery callbacks code.
  • Learn how to achieve reactivity and easily compose views with Vue.js and understand what it does behind the scenes.
  • Explore the core features of Vue.js with small examples, learn how to build dynamic content into preexisting web applications, and build Vue.js applications from scratch.

Description

Vue.js is one of the latest new frameworks to have piqued the interest of web developers due to its reactivity, reusable components, and ease of use. This book shows developers how to leverage its features to build high-performing, reactive web interfaces with Vue.js. From the initial structuring to full deployment, this book provides step-by-step guidance to developing an interactive web interface from scratch with Vue.js. You will start by building a simple application in Vue.js which will let you observe its features in action. Delving into more complex concepts, you will learn about reactive data binding, reusable components, plugins, filters, and state management with Vuex. This book will also teach you how to bring reactivity to an existing static application using Vue.js. By the time you finish this book you will have built, tested, and deployed a complete reactive application in Vue.js from scratch.

Who is this book for?

This book is perfect for novice web developer seeking to learn new technologies or frameworks and also for webdev gurus eager to enrich their experience. Whatever your level of expertise, this book is a great introduction to the wonderful world of reactive web apps.

What you will learn

  • Build a fully functioning reactive web application in Vue.js from scratch.
  • The importance of the MVVM architecture and how Vue.js compares with other frameworks such as Angular.js and React.js.
  • How to bring reactivity to an existing static application using Vue.js.
  • How to use plugins to enrich your applications.
  • How to develop customized plugins to meet your needs.
  • How to use Vuex to manage global application's state.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 13, 2016
Length: 334 pages
Edition : 1st
Language : English
ISBN-13 : 9781786461131
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 13, 2016
Length: 334 pages
Edition : 1st
Language : English
ISBN-13 : 9781786461131
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹400 billed monthly
Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
₹4000 billed annually
Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts
₹5000 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 10,949.97
Vue.js 2 Cookbook
₹3649.99
Learning Vue.js 2
₹3649.99
Vue.js 2 and Bootstrap 4 Web Development
₹3649.99
Total 10,949.97 Stars icon
Banner background image

Table of Contents

10 Chapters
Going Shopping with Vue.js Chevron down icon Chevron up icon
Fundamentals – Installing and Using Chevron down icon Chevron up icon
Components – Understanding and Using Chevron down icon Chevron up icon
Reactivity – Binding Data to Your Application Chevron down icon Chevron up icon
Vuex – Managing State in Your Application Chevron down icon Chevron up icon
Plugins – Building Your House with Your Own Bricks Chevron down icon Chevron up icon
Testing – Time to Test What We Have Done So Far! Chevron down icon Chevron up icon
Deploying – Time to Go Live! Chevron down icon Chevron up icon
What Is Next? Chevron down icon Chevron up icon
Solutions to Exercises Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(10 Ratings)
5 star 60%
4 star 30%
3 star 0%
2 star 10%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Aug 07, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Love it, the author does a good job of explaining things in a digestible way.
Amazon Verified review Amazon
Sherwin John C. Tragura Mar 12, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was looking for some help in understanding the MVC components of VUE application and this one laid out everything i need. Great book!
Amazon Verified review Amazon
amiralles Jul 08, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is awesome! The chapters are packed with code, advise, examples, tips, tricks, and a bit of humor here and there. I highly recommend this book to anyone trying to learn Vue.js.From a basic hello world to real world working app (two, actually), the author teaches you how to build, refactor, test and deploy your Vue.js apps.The code is really well written and easy to follow. I really enjoyed this book. Five starts!
Amazon Verified review Amazon
Pora Jan 30, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Friendly. Covers everything you need to know. Great for beginners, especially for picking up Vuex. Good for reference – !
Amazon Verified review Amazon
Herbal Apr 22, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a great book.. I advice you to buy this book.. It's very clear and the most important thing is It's not needed component base application because this book gives you the idea.. and naturally the necessary skills to begin developing immediately.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.