NuxtN
Nuxt2y ago
Eric

UseAsyncData with a request params defined by a computed property ?

Should that work ?
directusGetItems is a function I defined using the directus base url.
I would like to use the computed prop to modify the requestParams in the UI.

in this example, it's not reactive, but this non reactive version is not working. It doesn't fetch data on page load.

Is it possible to use useAsyncData with a computed prop ?
const requestParams = computed(() => {
    const params = {
        fields: [ '*' ],
        sort: '-date_created',
        limit: 25
    }

    return params;
});

const { data: meals } = await useAsyncData(
    "meals",
    async () => {
        const items = await directusGetItems('Meals', requestParams.value );

        return items;
    }, {
        watch: reqParam,
        server: true 
    }
);
Was this page helpful?