跳到主要內容

provideLocal

類別
匯出大小
227 B
上次變更
4 個月前

擴展了 provide,使其能夠調用 injectLocal 以在同一組件中獲取值。

用法

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

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

類型宣告

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

原始碼

原始碼文件

貢獻者

ZHAO Jin-Xiang
Anthony Fu

更新日誌

v12.0.0-beta.1 於 2024/11/21
0a9ed - feat!: 移除 Vue 2 支援,優化捆綁包並清理 (#4349)
v10.5.0 於 2023/10/7
cf757 - fix: vue 2 支援 provideLocal 和 injectLocal (#3464)
5d948 - feat(createInjectionState): 允許在同一組件中 provide 和 inject (#3387)

在 MIT 許可下發布。