Hej,

w rodzicu robię coś takiego
  1. onMounted(() => {
  2. getTransactions(paramsCurrentPeriod, erpTransactions); // tablica obiektów
  3. getTransactions(paramsPreviousPeriod, erpTransactionsPrevious); // tablica obiektów
  4. });

  1. class="col-md-12"
  2. v-for="item in erpTransactions"
  3. :key="item.salesRepresentativeId"
  4. >
  5. <SaleRepresentativeStats
  6. :data="item"
  7. :previous-data="erpTransactionsPrevious"
  8. />
  9. </div>

w pętli wyświetlam child przekazując do niego powyższe. Wewnątrz child potrzebuję wybrać jeden obiekt z previous-data gdzie item.id == previosu-data.id i z tym JAKBY sobie poradziłem tak

  1. import { defineComponent, reactive, PropType } from "vue";
  2.  
  3. interface Option {
  4. salesRepresentativeId: number;
  5. salesRepresentativeName: string;
  6. quantity: number;
  7. net: number;
  8. paymentLeft: number;
  9. }
  10.  
  11. interface Options extends Array<Option> {}
  12.  
  13. export default defineComponent({
  14. name: "sale-representative-stats",
  15. props: {
  16. data: {
  17. type: Object,
  18. required: true,
  19. },
  20. previousData: {
  21. type: Array as PropType<Options>,
  22. required: true,
  23. },
  24. },
  25. setup(props) {
  26. const prevData: object[] = reactive([]);
  27.  
  28. const findPreviousDataById = () => {
  29. const filtered = props.previousData.filter((obj) => {
  30. return obj.salesRepresentativeId === props.data.salesRepresentativeId;
  31. });
  32. prevData.push(filtered);
  33. console.log(prevData); // nie wiem dlaczego mam tutaj pusto
  34. };
  35.  
  36. onMounted(() => {
  37. findPreviousDataById();
  38. });
  39.  
  40. return {
  41. prevData,
  42. };
  43. },
  44. });

to co robi funkcja findPreviousData() chce pokazać na widoku. Niestety ta tablica obiektów jest pusta.
nie wiem czy nie jest to spowodowane jakimś cyklem życia komponentu? Iteruję i pokazuję child i jeszcze coś w nim robię co ma zostać wyświetlone. Niby normalka ale nie wiem co robię źle, że ten array jest pusty w console.log ?