Ver Fonte

feat: adiciona expose para get

ebagabee há 1 mês atrás
pai
commit
3b555ca4e4

+ 8 - 2
src/pages/products/ProductsPage.vue

@@ -47,7 +47,7 @@
       </div>
 
       <div v-show="currentTab === 'stock'">
-        <StockTab />
+        <StockTab ref="stockTabRef" />
       </div>
 
       <div v-show="currentTab === 'orders'">
@@ -58,7 +58,7 @@
 </template>
 
 <script setup>
-import { defineAsyncComponent, ref, shallowRef } from "vue";
+import { defineAsyncComponent, ref, shallowRef, watch } from "vue";
 import { useQuasar } from "quasar";
 
 import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
@@ -74,6 +74,12 @@ const search = ref("");
 const currentPage = ref(1);
 const totalPages = ref(1);
 const productsTabRef = shallowRef(null);
+const stockTabRef = shallowRef(null);
+
+watch(currentTab, (tab) => {
+  if (tab === "products") productsTabRef.value?.fetchProducts();
+  if (tab === "stock") stockTabRef.value?.refresh();
+});
 
 const tabs = [
   { name: "products", label: "Produtos" },

+ 2 - 0
src/pages/products/tabs/StockTab.vue

@@ -62,6 +62,8 @@ const columns = [
   },
 ];
 
+defineExpose({ refresh: () => tableRef.value?.refresh() });
+
 const handleEdit = (product) => {
   $q.dialog({
     component: AddEditStockProductDialog,