Create a component that uses provide/inject to share data between components without prop drilling.
Code Playground
JavaScript (V8)
Loading...
Console Output
// Output will appear here...
// For React: ReactDOM.createRoot(rootElement).render(<App />);
// For React: ReactDOM.createRoot(rootElement).render(<App />);
Recommended Answer
// Parent.vue
<template>
<Child />
</template>
<script setup>
import { provide } from 'vue';
import Child from './Child.vue';
provide('theme', 'dark');
</script>
// Child.vue
<template>
<p>Theme: {{ theme }}</p>
</template>
<script setup>
import { inject } from 'vue';
const theme = inject('theme');
</script>