コンテンツにスキップ

injectLocal

カテゴリ
エクスポートサイズ
最終変更日
先週

provideLocal を呼び出して、同じコンポーネントで値を提供できるように拡張された inject です。

使用方法

vue
<script setup>
import { injectLocal, provideLocal } from '@vueuse/core'

provideLocal('MyInjectionKey', 1)
const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
</script>

型定義

typescript
/**
 * On the basis of `inject`, it is allowed to directly call inject to obtain the value after call provide in the same component.
 *
 * @example
 * ```ts
 * injectLocal('MyInjectionKey', 1)
 * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
 * ```
 */
export declare const injectLocal: typeof inject

ソース

ソースドキュメント

貢献者

ZHAO Jin-Xiang
Anthony Fu
Anthony Fu

変更履歴

v12.0.0-beta.1 2024年11月21日
0a9ed - feat!: Vue 2 のサポートを削除し、バンドルを最適化してクリーンアップします (#4349)
v10.5.0 2023年10月7日
cf757 - fix: provideLocal と injectLocal の Vue 2 サポート (#3464)
5d948 - feat(createInjectionState): 同じコンポーネントでの provide と inject を許可 (#3387)

MITライセンスの下でリリースされています。