provideLocal
擴展了 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