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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章