Dependency Injection
asd
provide()
provide()
takes two arguments:
- key, which can be a string or a symbol
- value to be injected.
Similar to lifecycle hook registration APIs, provide() must be called synchronously during a component's setup() phase.
asd
provide()
takes two arguments:
Similar to lifecycle hook registration APIs, provide() must be called synchronously during a component's setup() phase.
<script setup>
import { ref, provide } from "vue";
import { fooSymbol } from "./injectionSymbols";
// provide static value
provide("foo", "bar");
// provide reactive value
const count = ref(0);
provide("count", count);
// provide with Symbol keys
provide(fooSymbol, count);
</script>