跳转到内容

injectLocal

类别
导出大小
229 B
最近更改
3 个月前

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

用法

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

源码

源码文档

贡献者

Anthony Fu
ZHAO Jin-Xiang
Anthony Fu

更新日志

v12.1.0 on 12/22/2024
b08a9 - 修复:允许注入到应用上下文
v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: 移除 Vue 2 支持,优化打包并清理 (#4349)
v10.5.0 on 10/7/2023
cf757 - 修复:为 provideLocal 和 injectLocal 提供 Vue 2 支持 (#3464)
5d948 - feat(createInjectionState): 允许在同一组件中提供和注入 (#3387)

在 MIT 许可证下发布。