Appendix B. Solutions to chapter exercises

 

Solutions to the exercise questions in chapters 212 are listed here.

Chapter 2

  • In section 2.4 we created a filter for the price. Can you think of any other filters that might be helpful?

Filters in Vue.js are commonly used to do text filtering. One filter you may want to add is a way to capitalize the product title.

Chapter 3

  • Earlier in the chapter we looked at computed properties and methods. What are the differences?

Computed properties are useful when you’re trying to derive a value. The value will be automatically updated whenever any of its underlying values are updated. It’s also cached to avoid repetitively calculating a value that doesn’t need to be recalculated when it hasn’t changed, as in a loop. Note that methods are functions bound to the Vue instance. They only evaluate when they’re explicitly called. Unlike computed properties, methods accept parameters. Computed properties cannot. Methods are useful in the same situations where any JavaScript functions would be useful. An application isn’t effective without supporting robust user interactions.

Chapter 4

  • How does two-way data binding work? When should you use it in your Vue.js application?

In the simplest terms two-way data binding works when updates in the model update the view, and updates in the view update the model. Two-way data binding should be used throughout your application when dealing with forms and inputs.

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Chapter 11

Chapter 12

 

Cheat sheet

Custom events

Lifecycle hooks

beforeCreate     beforeUpdate
created          updated
beforeMount      beforeDestroy
mounted          destroyed

 

Cheat sheet