Slide 6
Slide 6 text
InjectionKeyͷར༻
Layout
Main
ArticleEditor
export const userInjectionKey =
Symbol() as InjectionKey;
import { userInjectionKey }
from './InjectionKey';
const me: User = { name: 'Jack' };
provide(userInjectionKey, me);
import { userInjectionKey }
from './InjectionKey';
const me = inject(userInjectionKey);
console.log(me?.name);
Layout.vue
ArticleEditor.vue
InjectionKey.ts
InjectionKeyʹΩϟετͨ͠
SymbolΛFYQPSU
inject()ͷฦ٫ܕ
User|undefinedͱͳΔ