Skip to content

provideLocal ​

Category
Export Size
227 B
Last Changed
5 minutes ago

扩展了 provide 方法,使其能够通过调用 injectLocal 在同一组件中获取值。

用法 ​

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

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

Type Declarations ​

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

Source ​

Source • Docs

Contributors ​

jojo

Changelog ​

No recent changes

Released under the MIT License.