Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore 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
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/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...

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:

MVVM architectural pattern

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:

MVVM architectural pattern

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...

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...

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...

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...

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...

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
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ 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
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ 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 €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ 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 €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 110.97
Vue.js 2 Cookbook
€36.99
Learning Vue.js 2
€36.99
Vue.js 2 and Bootstrap 4 Web Development
€36.99
Total 110.97 Stars icon

Table of Contents

10 Chapters
1. Going Shopping with Vue.js Chevron down icon Chevron up icon
2. Fundamentals – Installing and Using Chevron down icon Chevron up icon
3. Components – Understanding and Using Chevron down icon Chevron up icon
4. Reactivity – Binding Data to Your Application Chevron down icon Chevron up icon
5. Vuex – Managing State in Your Application Chevron down icon Chevron up icon
6. Plugins – Building Your House with Your Own Bricks Chevron down icon Chevron up icon
7. Testing – Time to Test What We Have Done So Far! Chevron down icon Chevron up icon
8. Deploying – Time to Go Live! Chevron down icon Chevron up icon
9. What Is Next? Chevron down icon Chevron up icon
A. 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




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
WiltDurkey Feb 17, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I quite liked it. Bear in mind when reading this review where I am coming from:- somewhat of a JS newbie, but have been working with it for a while using Jquery to do front-end stuff on a Django app, all with require.js and pre-es6 stuff (i.e. no Node.js or equivalent).- my frontend code was a tangled mess and really I needed to put in something cleaner. Vue fit the bill, because I could read and follow its introductory code right away, unlike React/Angular/Ember. Simple _and_ powerful is always a winning combination in my book. And it didn't seem to _require_ an SPA approach.- but... Vue, especially 2.0, is newer and has less books or online materials, so I needed something to hold my hands going from basic Hello World type examples to something more complex. All the same, I wanted basic stuff because SPA type examples wouldn't apply and I was more interested in the concepts.Pheew! Sorry for the long preamble, but it'll give you an idea of what motivates my review.First, it is quite well structured and easy to follow. You have the obligatory test applications (2 or 3 of them) and they start out using basic Vue features and then, as you go through the chapters and new Vue concepts are introduced, you see them reused, elegantly, in the apps. The apps, IMHO, strike the right balance between not being totally trivial and providing you some insight on what a real Vue-based app might look like. Vs dumping you off at the deep end with some complex code that forces you to think about the app's structure rather than what Vue is doing.Second, Vue itself mostly doesn't care that much about being used as a simple CDN-sourced library or whether it comes from a more sophisticated Node-based system. So I was following the book writing my JS as usual. But as you start looking at reusing Vue Components, then yes, Node or similar is the more natural (and less complex!) way to go. At some point, the book goes into setting up a basic Node+Webpack and points you where to download its own sample configuration. As I had node + npm already installed, I gave it a try and, lo and behold, the sample app ran perfectly. So I kind of stumbled into modern JS best practices following it along. Hey, this is about 5 pages, so no great amount of unnecessary content if you already use Webpack. But a brilliant leg up if you don't and would like to.While it builds on basic concepts, it is not dumbed down - for example there is a detailed explanation of how Vue reactivity works under the covers, starting with how you would achieve it by wrapping attributes in getters and setters.The development concepts conclude with an intro to Vuex, and how to use it to federate data and state among components. This is also important, because, as good as Vue is, it doesn't have a builtin system (events aside) to wire components together and components are compartmentalized by design. That's what Vuex is for. So you can consider Vue+Vuex as the need-to-have for real apps. Again, the concepts are well explained and easy to follow.There is some further material about testing as well. So quite a comprehensive coverage of what it covers. (Should have included 'slots' though).Conclusion: I think that, if you were coming in as an experienced Angular/React/etc... SPA-type dev, then not seeing Vue-Router/Resource and the focus on just the basics might hold you back a bit. You would certainly benefit from the way this book complements the, pretty darn good, official Vue documentation. But you might also be able to figure these things out on your own, without this book. Either way some of the more sophisticated stuff is out of scope here. So it's really a choice between are you a self-researcher or I-prefer-a-book type of guy.To be honest, while I got it at a discount, the full price is somewhat steep - but it's supply and demand stuff - few Vue books, premium price for now (c.f. the dude with the 40page/25$ book) . If you are finding your way into modern JS frontend libraries, Vue's simplicity is appealing and this book is very helpful in gently getting you up to speed.p.s. For some reason the Kindle Paperwhite version uses the smallest font ever. Whenever reading it, I am forced to switch to the largest or next-to-largest size setting, at which point it works well. But then I have to switch it back to the smaller sizes I usually use for other books. No such problem on the iPad Kindle app.
Amazon Verified review Amazon
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
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.