[Vue warn]: injection "a" not found.
app.vue
<Menu>
<MenuItem>
<i class="fa fa-home"></i>
<small>Navigation</small>
</MenuItem>
</Menu>
menu.vue
<script setup lang="ts">
import { provide } from 'vue'
import type { InjectionKey } from 'vue'
const key = Symbol() as InjectionKey<Function>
const a = (name: string) => {
return name
}
provide(key, a)
</script>
<template>
<ul class="menu">
<slot></slot>
</ul>
</template>
menu-item.vue
<script setup lang="ts">
import { inject, ref } from 'vue'
const a = inject('a')
console.log(a); // injection "a" not found.
const isActive = ref(false)
</script>
<template>
<li :class="{active: isActive}">
<a href="javascript:void(0);">
<slot></slot>
</a>
</li>
</template>
- 64
四川provide的key没有与inject的key('a')对应
这是官网的用法
https://v3.cn.vuejs.org/guide...