How can I get the seo of my Nuxt app from one external api, in this case strapi, and use it in my app, actually I have this, //
enter code here
import { getEnv } from "../src/utils";
import { useState } from "#app"
export default defineNuxtPlugin(async (nuxtApp) => {
const config = getEnv();
const currentPath = nuxtApp.ssrContext?.event.node.req.url || "unknown-path";
const lang = currentPath.split("/")[1]
try {
const { data, error } = await useAsyncData(
"mediaPagina-locales",
() =>
$fetch(`${config.API_URL}/api/pages?locale=${lang}&populate=*`, {
method: "GET",
}),
{
server: true,
lazy: false,
default: () => null,
stale: 60 * 1000 * 60 * config.LOCAL_CACHE_HOURS,
}
);
if (error.value) {
console.warn("⚠️ Error:", error.value);
return;
}
if (!data.value?.data) {
console.warn("⚠️ Error.");
return;
}
const pages = data.value.data;
console.log("✅ Error", pages.length, "entries");
useState("cookies_locales", () => pages.filter((i: any) => i?.page === "cookies"));
useState("cookies_seo_locales", () => pages.filter((i: any) => i?.page === "cookies/seo"));
} catch (err) {
console.error("❌ Error fetchPageData:", err);
}
});
enter code here //but when I try to access to the seo useState() in the front
const contactSeo = useState('cookies_seo_locales')
const seo = computed(() => unref(cookies)[0]);
This don't work because the variable is only ready on after the hydratation. There is a way for do this?