provide() Provide a Dependency to Descendants

Last updated: 2026-10-22

provide() Provide a Dependency to Descendants

provide() exposes data from an ancestor so any descendant can inject() it — no prop drilling through every level.

GroupDependency Injection
KindAPI
ScopeComponent
Vue Version3.0+
SSR SupportYes

📝 Syntax

provide("theme", ref("dark"))
provide("config", readonly(config))   // recommended: provide readonly

⚙️ Arguments

keyA string or Symbol key
valueAny value (refs stay reactive across the boundary)

Returns:None

▶ Example

Edit the code below and see the live result:

Output:

The child shows 'Injected theme: dark'.

💡 Key Points

💡 Tip Provide refs or reactive objects to keep reactivity; plain values are snapshots.
⚠️ Warning Provide readonly to stop any descendant from mutating ancestor state.
ℹ️ Note Prefer Symbol keys in large projects to avoid name clashes.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q How is it different from props?
A Props are explicit level by level; provide/inject skips levels for theme or config style context.
Q Can provided data be mutated?
A Technically yes, so provide readonly state or mutation helpers.
Q Can keys clash?
A The nearest provider wins; Symbol keys avoid clashes entirely.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏