跳到主要内容

injectLocal

分类
导出大小
246 B
上次更改
上个月

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

用法

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

类型声明

ts
/**
 * 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
 * ```
 *
 * @__NO_SIDE_EFFECTS__
 */
export declare const 
injectLocal
: typeof
inject

来源

来源文档

贡献者

Anthony Fu
ZHAO Jin-Xiang
Zhaokun
Arthur Darkstone
SerKo
Anthony Fu

更新日志

v14.0.0
51872 - fix(shared): 在 vapor 模式下支持 provideLocal/injectLocal (#5050)
v13.6.0
d32f8 - refactor: 为所有纯函数添加 @__NO_SIDE_EFFECTS__ 注释 (#4907)
v12.1.0
b08a9 - fix: 允许注入到应用程序上下文
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
v10.5.0
cf757 - fix: Vue 2 对 provideLocal 和 injectLocal 的支持 (#3464)
5d948 - feat(createInjectionState): 允许在同一组件中进行 provide 和 inject (#3387)

根据 MIT 许可证发布。