I'm modifing my strapi and nuxt site to find my post by slug instead of id https://forum.strapi.io/t/strapi-v4-search-by-slug-instead-id/13469/21
this is working, but when i do my axios request in _slug.vue the url is correct but it doesn't save the info in my response variable, in my browser console says can't read data from undefined, checked the url is correct and in my strapi console i have everything ok.
async asyncData({ route, i18n, title, description }) {
try {
const locale = i18n.locale;
const qs = require("qs");
const query = qs.stringify(
{
populate: "*",
publicationState: "live",
locale: [locale],
},
{
encodeValuesOnly: true,
}
);
const response = await axios.get(
`http://localhost:1337/api/posts/${route.params.slug}/?&` +
query
);
console-log(response)
let post = response.data;
if (locale != post.data.attributes.locale) {
post.data.attributes.localizations.data.forEach((element) => {
if (element.attributes.locale === locale) {
title = element.attributes.title;
description = element.attributes.description;
}
});
} else {
title = post.data.attributes.title;
description = post.data.attributes.description;
}
return { post, title, description };
} catch (error) {
this.error = error.response.data.error.details.errors;
}
},
Any ideas? thanks