Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Vue.js 2

You're reading from   Learning Vue.js 2 Learn how to build amazing reactive web applications easily with Vue.js

Arrow left icon
Product type Paperback
Published in Dec 2016
Publisher Packt
ISBN-13 9781786469946
Length 334 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Olga Filipova Olga Filipova
Author Profile Icon Olga Filipova
Olga Filipova
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Going Shopping with Vue.js FREE CHAPTER 2. Fundamentals – Installing and Using 3. Components – Understanding and Using 4. Reactivity – Binding Data to Your Application 5. Vuex – Managing State in Your Application 6. Plugins – Building Your House with Your Own Bricks 7. Testing – Time to Test What We Have Done So Far! 8. Deploying – Time to Go Live! 9. What Is Next? A. Solutions to Exercises

Parent-child components' communication, events, and brain teaser


Remember our shopping list application? Do you remember our ChangeTitleComponent and how we ensured that typing in its input box would affect the title of the shopping list that belongs to the parent component? You remember that each component has its own scope, and the scope of the parent component cannot be affected by children components. Thus, in order to be able to propagate the changes from inside the children components to the parent components, we used events. Putting it very simply, you can call the $emit method from the child component with the name of the event being dispatched and listen to this event within the v-on directive on the parent component.

If it is a native event, such as input, it's even more simple. Just bind the needed attribute to the child component as a v-model and then call the $emit method with the name of the event (for example, input) from the child component.

Actually, this is exactly what we...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime