You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use vite-ssg with an external CMS and fetch data from the CMS only on build, but not again on the client side when the page is loaded. I believe this is discussed in this issue, and the proposed solution looks like this:
importaxiosfrom'axios'const{ get }=axios// The data we will showconstrepo=ref<RepoData|null>(null)// A function to get the dataconstfetch=async()=>{constdata=awaitget(`https://api.github.com/repos/nickgraffis/petite-vin`)repo.value=data.data}// Only run this function client side if we don't have a value assigned to repo yet// if repo already has a value, it was fetched during buildif(!repo.value)fetch()// During the build, fetch the data before building the componentonServerPrefetch(async()=>{awaitfetch()})
This works in that it does fetch data at build time, and inserts it into the HTML. But the API is still called again in the browser.
Is there any way around this or would I need to use a framework like Nuxt to achieve what I'm looking for?
The text was updated successfully, but these errors were encountered:
onServerPrefetch only useful in SSR mode,
you should check repo is null in onMounted,
if rep is null , that is SSR , you should not call fetch in onMounted
I'm trying to use vite-ssg with an external CMS and fetch data from the CMS only on build, but not again on the client side when the page is loaded. I believe this is discussed in this issue, and the proposed solution looks like this:
This works in that it does fetch data at build time, and inserts it into the HTML. But the API is still called again in the browser.
Is there any way around this or would I need to use a framework like Nuxt to achieve what I'm looking for?
The text was updated successfully, but these errors were encountered: