Fork me on GitHub

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')

 

posted @ 2022-09-28 15:32  欢欢11  阅读(1079)  评论(0编辑  收藏  举报