Skip to content

Commit

Permalink
feat(Data Fetching): Use NUXT Data Fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
sfxcode committed Apr 24, 2022
1 parent 9d3da27 commit 1e0e70d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pages/prime/table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

</template>
</DataTable>

<Button class="mt-6" label="Update Products" @click="update"/>
</div>
</template>

Expand All @@ -58,18 +60,17 @@ filters.value = {
'inventoryStatus': {value: null, matchMode: FilterMatchMode.STARTS_WITH},
};
function updateTableData() {
tableData.value = dataStore.products as Array<any>;
}
// mounted
onMounted(async () => {
await dataStore.initData()
updateTableData();
log.debug(dataStore.products);
const {data:products, refresh:refreshProducts } = await useAsyncData('products', () => $fetch('/data/products.json'), {server: false})
});
watch(products, (newProducts) => {
log.debug("number of products loaded: " + newProducts.data.length)
tableData.value = newProducts.data
})
const update = () => {
refreshProducts();
}
</script>

Expand Down
36 changes: 36 additions & 0 deletions pages/store.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<div class='card'>
<h5>Store Settings</h5>
<h5 class='font-bold text-2xl mb-4 text-blue-600'>Primevue Theme Store</h5>
<div class='grid grid-cols-2 gap-4'>
<div>Theme Name</div>
<div>{{ themeStore.themeName }}</div>
<div>Theme Color</div>
<div>{{ themeStore.themeColor }}</div>
</div>

<h5 class='font-bold text-2xl mb-4 text-blue-600'>Data Store</h5>
<span class='text-xs'>Example of a Cached Pinia Store, data is cached in local storage ...</span>
<div class='grid grid-cols-2 mt-6 gap-4'>
<div>Customers</div>
<div>{{ dataStore.customers.length }}</div>
<div>Products</div>
<div>{{ dataStore.products.length }}</div>
</div>

</div>
</template>

<script setup lang='ts'>
import { useDataStore, useThemeStore } from '@/stores';
const themeStore = useThemeStore();
const dataStore = useDataStore();
onMounted(async () => {
await dataStore.initData()
})
</script>

<style scoped></style>

0 comments on commit 1e0e70d

Please sign in to comment.