// 爷组件 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')
标签:const,computed,provide,getList,state,inject,vue3 From: https://www.cnblogs.com/huanhuan55/p/16738269.html