vue3中inject无法获取provide传递的最新的值
// 爷组件
import { defineComponent, reactive, toRefs, onMounted, provide ,computed} from 'vue';
const state = reactive({
tableData: [],
});
// 因为数据是异步的所以需要使用computed
provide('myList',computed(() => state.tableData))
const getList = async () => {
const res = await getList();
state.tableData = res.list || []
}
onMounted(() => {
getList ();
});
// 孙组件 import { defineComponent,inject } from 'vue';
const mylist = inject('myList')


浙公网安备 33010602011771号