feat: 产品页的组合式API
All checks were successful
deploy to server / build-and-deploy (push) Successful in 5m11s

- 为product和product-list添加组合式API
This commit is contained in:
2025-10-16 16:02:20 +08:00
parent 6c76d81a40
commit 227b537a0f
5 changed files with 159 additions and 157 deletions

View File

@ -0,0 +1,42 @@
import { readItems } from '@directus/sdk';
export const useProductList = () => {
const { $directus } = useNuxtApp();
const { getDirectusLocale } = useLocalizations();
const locale = getDirectusLocale();
return useAsyncData(`product-list-${locale}`, async () => {
return await $directus.request(
readItems('products', {
fields: [
'id',
{ translations: ['id', 'name', 'summary'] },
'cover',
{
product_type: [
'id',
{
translations: ['id', 'name'],
},
],
},
],
deep: {
translations: {
_filter: {
languages_code: { _eq: locale },
},
},
product_type: {
translations: {
_filter: {
languages_code: { _eq: locale },
},
},
},
},
})
);
});
};