BeerDuck
moving from Nuxt2 useFetch to Nuxt3 useAsyncData - how would you refactor this example?
watch(() => watachablevalue, (newVal,oldVal) => {
//use variable or do something when variable changes.
});
This keeps track on variable changes if i am correct.32 replies
moving from Nuxt2 useFetch to Nuxt3 useAsyncData - how would you refactor this example?
const homePageLoaded = ref(false);
const homePage = ref(1);
async function loaddata(){
const{ data: thedata } = useAsyncData( async () => {
return await loadHomePage();
});
homePage.value=thedata;
homePageLoaded.value = true;
}
await loaddata();
32 replies
moving from Nuxt2 useFetch to Nuxt3 useAsyncData - how would you refactor this example?
I try to explain what happens, and maybe it is not 100% correct but. Your code within your asyncdata will not be executed a second time. because the whole function gets skipped, and the data: homepage gets filled in without executing the function again. This is why everything that happens within the function does not get executed a second time. What i think you just want is an normal function around it.
32 replies