#Reload data

5 messages · Page 1 of 1 (latest)

severe oar
#

Hello, i recently came across a problem when reloading the /admin page.
My problem is that my js function useFetch() is not triggered when I reload the page manually, so the data of my ref() function dashboardData is empty
It works fine when navigating through my app. What should i do to to fix it?

<script setup>

const {
    dashboardData,
    getDashboardData,
} = useDashboard()

await getDashboardData()

</script>
const fetchSanctum = async (url, options = {method: 'GET'}) => {
        const router = useRouter()
        const userStore = useAuthStore()
        const config = useRuntimeConfig()
        let token = useCookie('XSRF-TOKEN').value

        if (options.method !== 'GET' && !token) {
            await useFetch('/sanctum/csrf-cookie', {
                method: 'GET',
                credentials: 'include',
                baseURL: config.public.baseURL,
            })

            token = useCookie('XSRF-TOKEN').value
        }

        return await useFetch(url, {
            ...{
                credentials: 'include',
                baseURL: config.public.baseURL + '/api',
                headers: {
                    'X-XSRF-TOKEN': token,
                    'Accept': 'application/json',
                    'X-Requested-With': 'XMLHttpRequest',
                    'Access-Control-Allow-Credentials': true,
                },
            }, ...options
        })
    }
valid wing
#

Had the same issue. It appears that you have to fetch the data on the server first

severe oar
#

This seems to happen when ssr mode is set to true, how could i fetch the data on the server first ?

valid wing
#

You can create an api route in a server folder

#

Or you can use onServerPrefetch vue hook