Skip to content

injectLocal

类别
导出体积
246 B
上次更改
last week

扩展了 inject,能够调用 provideLocal 在同一组件中提供值。

用法

vue
<script setup>
import { 
injectLocal
,
provideLocal
} from '@vueuse/core'
provideLocal
('MyInjectionKey', 1)
const
injectedValue
=
injectLocal
('MyInjectionKey') // injectedValue === 1
</script>

类型声明

ts
/**
 * 在 `inject` 的基础上,允许直接调用 `inject` 来获取在同一组件中调用 provide 后的值。
 *
 * @example
 * ```ts
 * injectLocal('MyInjectionKey', 1)
 * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
 * ```
 *
 * @__NO_SIDE_EFFECTS__
 */
export declare const 
injectLocal
: typeof
inject

源码

源码文档

贡献者

一纸忘忧
Anthony Fu
ZHAO Jin-Xiang
Arthur Darkstone
SerKo
Anthony Fu

更新日志

d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
b08a9 - fix: allow inject to app context
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
cf757 - fix: vue 2 support for provideLocal and injectLocal (#3464)
5d948 - feat(createInjectionState): allow provide and inject in same component (#3387)