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 now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Front-End Development Projects with Vue.js
Front-End Development Projects with Vue.js

Front-End Development Projects with Vue.js: Learn to build scalable web applications and dynamic user interfaces with Vue 2

Arrow left icon
Profile Icon Raymond Camden Profile Icon Clifford Gurney Profile Icon Maya Shavin Profile Icon Philip Kirkbride Profile Icon Hugo Di Francesco +1 more Show less
Arrow right icon
$20.98 $29.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8 (10 Ratings)
eBook Nov 2020 774 pages 1st Edition
eBook
$20.98 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Raymond Camden Profile Icon Clifford Gurney Profile Icon Maya Shavin Profile Icon Philip Kirkbride Profile Icon Hugo Di Francesco +1 more Show less
Arrow right icon
$20.98 $29.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8 (10 Ratings)
eBook Nov 2020 774 pages 1st Edition
eBook
$20.98 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$20.98 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.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
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Front-End Development Projects with Vue.js

2. Working with Data

Overview

In this chapter, you will expand on what you learned in the previous chapter by introducing more ways to control data inside Vue components. You will learn how to set up advanced watchers to observe data changes inside your components, and utilize Vue's powerful reactive data feature, computed data properties, to concisely output just the data you need in your template. You will also be able to utilize asynchronous methods to fetch data for your Vue components.

By the end of this chapter, you will be able to watch, manage, and manipulate data from various sources in your Vue.js components.

Introduction

In the previous chapter, you were introduced to the concepts of single-file components and the Vue API, which provides access to methods, directives, and data properties. Building on these foundations, we will be introducing computed properties, which, like data properties, are reactive in the UI but can perform powerful calculations, and their results are cacheable, increasing the performance of your project. When building e-commerce stores, you will usually want to calculate pricing and cart items reactively as users interact with your UI, which in the past would need to be achieved without a page reload using something like jQuery. Vue.js makes short work of these common frontend tasks by introducing computed properties that react immediately to frontend user input.

Let's begin by introducing reactive data that can be computed on the fly and understanding how to call and manipulate asynchronous data.

Computed Properties

Computed properties are a unique data type that will reactively update when source data used within the property is updated. They may look like a Vue method, but they are not. In Vue, we can track changes to a data property by defining them as a computed property, add custom logic within this property, and use it anywhere within the component to return a value. Computed properties are cached by Vue, making them more performant for returning data than a data prop or using a Vue method.

Instances where you may use a computed property include but are not limited to:

  • Form validation:

    In this example, an error message will appear when the total data property is less than 1. The computed property for total will update every time a new piece of data is added to the items array:

    <template>
        <div>{{errorMessage}}</div>
    </template>
    <script>
        export default {
         ...

Computed Setters

In the last exercise, you saw how to write maintainable and declarative computed properties that are reusable and reactive and can be called anywhere within your component. In some real-world cases when a computed property is called, you may need to call an external API to correspond with that UI interaction or mutate data elsewhere in the project. The thing that performs this function is called a setter.

Computed setters are demonstrated in the following example:

data() {
  return {
    count: 0
  }
},
computed: {
    myComputedDataProp: {
      // getter
      get() {
        return this.count + 1
      },
      // setter
      set(val) {
        this.count = val - 1
 ...

Watchers

Vue watchers programmatically observe component data and run whenever a particular property changes. Watched data can contain two arguments: oldVal and newVal. This can help you when writing expressions to compare data before writing or binding new values. Watchers can observe objects as well as string, number, and array types. When observing objects, it will only trigger the handler if the whole object changes.

In Chapter 1, Starting Your First Vue Project, we introduced life cycle hooks that run at specific times during a component's lifespan. If the immediate key is set to true on a watcher, then when this component initializes it will run this watcher on creation. You can watch all keys inside of any given object by including the key and value deep: true (default is false) To clean up your watcher code, you can assign a handler argument to a defined Vue method, which is best practice for large projects.

Watchers complement the usage of computed data since they...

Deep Watching Concepts

When using Vue.js to watch a data property, you can purposefully observe keys inside an object for changes, rather than changes to the object itself. This is done by setting the optional deep property to true:

data() {
  return {
      organization: {
        name: 'ABC',
        employees: [
            'Jack', 'Jill'
        ]
      }
  }
},
watch: {
    organization: {
      handler: function(v) {
        this.sendIntercomData()
      },
      deep: true,
      immediate: true,
  &...

Methods versus Watchers versus Computed Props

In the Vue.js toolbox, we have access to methods, watchers, and computed properties. When should you use one or the other?

Methods are best used to react to an event occurring in the DOM, and in situations where you would need to call a function or perform a call instead of reference a value, for example, date.now().

In Vue, you would compose an action denoted by @click, and reference a method:

<template>
    <button @click="getDate">Click me</button>
</template>
<script>
export default {
    methods: {
        getDate() {
            alert(date.now())
        }
    }
}
</script>

Computed props are best used when reacting to data updates or for composing complicated expressions for us...

Async Methods and Data Fetching

Asynchronous functions in JavaScript are defined by the async function syntax and return an AsyncFunction object. These functions operate asynchronously via the event loop, using an implicit promise, which is an object that may return a result in the future. Vue.js uses this JavaScript behavior to allow you to declare asynchronous blocks of code inside methods by including the async keyword in front of a method. You can then chain then() and catch() functions or try the {} syntax inside these Vue methods and return the results.

Axios is a popular JavaScript library that allows you to make external requests for data using Node.js. It has wide browser support making it a versatile library when doing HTTP or API requests. We will be using this library in the next exercise.

Exercise 2.06: Using Asynchronous Methods to Retrieve Data from an API

In this exercise, you will asynchronously fetch data from an external API source and display it in the...

Summary

In this chapter, you were introduced to Vue.js computed and watch properties, which allow you to observe and control reactive data. You also saw how to use methods to asynchronously fetch data from an API using the axios library and how to flatten the data to be more usable within the Vue template using computed props. The differences between using methods and computed and watch properties were demonstrated by building search functionality using each method.

The next chapter will cover the Vue CLI and show you how to manage and debug your Vue.js applications that use these computed properties and events.

Left arrow icon Right arrow icon

Key benefits

  • Learn how to make the best use of the Vue.js 2 framework and build a full end-to-end project
  • Build dynamic components and user interfaces that are fast and intuitive
  • Write performant code that “just works” and is easily scalable and reusable

Description

Are you looking to use Vue 2 for web applications, but don't know where to begin? Front-End Development Projects with Vue.js will help build your development toolkit and get ready to tackle real-world web projects. You'll get to grips with the core concepts of this JavaScript framework with practical examples and activities. Through the use-cases in this book, you'll discover how to handle data in Vue components, define communication interfaces between components, and handle static and dynamic routing to control application flow. You'll get to grips with Vue CLI and Vue DevTools, and learn how to handle transition and animation effects to create an engaging user experience. In chapters on testing and deploying to the web, you'll gain the skills to start working like an experienced Vue developer and build professional apps that can be used by other people. You'll work on realistic projects that are presented as bitesize exercises and activities, allowing you to challenge yourself in an enjoyable and attainable way. These mini projects include a chat interface, a shopping cart and price calculator, a to-do app, and a profile card generator for storing contact details. By the end of this book, you'll have the confidence to handle any web development project and tackle real-world front-end development problems.

Who is this book for?

This book is designed for Vue.js beginners. Whether this is your first JavaScript framework, or if you’re already familiar with React or Angular, this book will get you on the right track. To understand the concepts explained in this book, you must be familiar with HTML, CSS, JavaScript, and Node package management.

What you will learn

  • Set up a development environment and start your first Vue 2 project
  • Modularize a Vue application using component hierarchies
  • Use external JavaScript libraries to create animations
  • Share state between components and use Vuex for state management
  • Work with APIs using Vuex and Axios to fetch remote data
  • Validate functionality with unit testing and end-to-end testing
  • Get to grips with web app deployment

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 27, 2020
Length: 774 pages
Edition : 1st
Language : English
ISBN-13 : 9781838981044
Vendor :
ECMA International
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
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Nov 27, 2020
Length: 774 pages
Edition : 1st
Language : English
ISBN-13 : 9781838981044
Vendor :
ECMA International
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 137.97
Front-End Development Projects with Vue.js
$43.99
Vue.js 3 Cookbook
$48.99
Node Cookbook
$44.99
Total $ 137.97 Stars icon

Table of Contents

14 Chapters
1. Starting Your First Vue Project Chevron down icon Chevron up icon
2. Working with Data Chevron down icon Chevron up icon
3. Vue CLI Chevron down icon Chevron up icon
4. Nesting Components (Modularity) Chevron down icon Chevron up icon
5. Global Component Composition Chevron down icon Chevron up icon
6. Routing Chevron down icon Chevron up icon
7. Animations and Transitions Chevron down icon Chevron up icon
8. The State of Vue.js State Management Chevron down icon Chevron up icon
9. Working with Vuex – State, Getters, Actions, and Mutations Chevron down icon Chevron up icon
10. Working with Vuex – Fetching Remote Data Chevron down icon Chevron up icon
11. Working with Vuex – Organizing Larger Stores Chevron down icon Chevron up icon
12. Unit Testing Chevron down icon Chevron up icon
13. End-to-End Testing Chevron down icon Chevron up icon
14. Deploying Your Code to the Web Chevron down icon Chevron up icon

Customer reviews

Most Recent
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8
(10 Ratings)
5 star 90%
4 star 0%
3 star 10%
2 star 0%
1 star 0%
Filter icon Filter
Most Recent

Filter reviews by




angelbearuk May 31, 2022
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I found examples in the first chapter to be confusing, where the author doesn't explain what a Vue component actually does and how that component interacts with data. Even the conditional example isn't explained, the Vue syntax for is not intuitive. I don't think this book is going to be of much practical use.
Amazon Verified review Amazon
Life Is Great Jul 05, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book is well organized and the flow works well in leading the reader to a core understanding of Vue -- from the basics to state management, routing and testing. If there is any improvement it would be in the sample code structure -- provide separate starting point and final code for the exercises.
Amazon Verified review Amazon
Keith Tachibana May 13, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This was a great introduction to Vue.js, and given its steady rise in popularity recently, this was a necessary resource for me to show off some coding projects using Vue.js, stuff that would make me stand out as an applicant when applying for jobs in software engineering or web development. Even if you are a seasoned developer who has been using only Angular.js or React.js, you will also get something out of this book that will impress other developers. When I was in graduate school studying computer science, most of the books that were required reading were so dry and hard to follow. But this was the complete opposite and a breath of fresh air!
Amazon Verified review Amazon
Camy Chhetri Apr 29, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have worked on VueJS for more than 3 years and I really wish that I had read this book when I started learning VueJS. This book covers basic concepts such as data binding, passing data properties, and Vue lifecycle hooks with helpful examples. I was not expecting this book to explain routing, state management, animations, and testing in such a simple and effective manner. I enjoyed reading this book. I would recommend this book to anyone from beginner to advanced VueJS/JavaScript/any frontend developers.
Amazon Verified review Amazon
Michael Apr 27, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is very friendly to beginners. There are tons of examples on the various concepts of Vue and there's a lot of starter code to work through and reference. I think the comparisons to other frameworks could have been done a bit more in detail and likely with some sort of graphical element. I appreciated the author showing how to setup different styling aspects as sometimes that can be a tricky thing.As someone who has never thoroughly worked with Vue, I can say I am more confident with the framework after having worked through this book.
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.