Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

help: Before mount, await useFetch #741

Open
@arkhamvm

Description

@arkhamvm

📚 What are you trying to do? Please describe.
On the client, before component will be mounted, I want to completely load data.

🔍 What have you tried?

	setup() {
		const pageData = ref<PageData | null>(null);

		const {params, error} = useContext();
		useFetch(async () => {
			const pageDataStore = usePageDataStore();

			await pageDataStore.fetchDataById(params.value.id);

			pageData.value = pageDataStore.currentData;
			if (null === pageData.value) {
				return error({statusCode: 404, message: 'Not Found'});
			}
		});

		return {
			pageData,
		};
	},

ℹ️ Additional context
According to Nuxt lifecycle, I expect that useFetch will be completely done, like fetch does.
This is especially distressing in pageComponents - page transition is complete, but page is empty and waiting for data.

https://nuxtjs.org/_nuxt/image/de48ca.svg

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions