Lesson 19 — Provide / inject
Hand data to any descendant
provide(key, value) in a parent makes a value available to every component inside it, at any depth. A child reads it with inject(key). This skips prop drilling (passing a prop through components that do not need it). Note that a component cannot inject what it provides itself — it must be a child. If you provide a ref, children see its changes.
// parent: provide("user", currentUser)
// any child: const user = inject("user")
Why it matters: themes, the logged-in user and app settings are shared this way.
Provide theme from the parent and inject it in ThemeLabel. It should show "Theme: dark", then "Theme: light" after Switch.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based Vue.js Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for Vue.js Foundations books — check the publication year so the examples match current versions.
Search Amazon →