My code deosn’t work because of the fetching.
Hello I’m trying to fetch the articles page with the wordpress API.
<script> export default { async asyncData({ params, error, app }) { console.log("Fetching data for slug:", params.slug); const url =link_here;
try {
const response = await app.$axios.$get(url);
if (!response || response.length === 0) {
error({ statusCode: 404, message: 'Article not found' });
return { article: null };
}
return { article: response[0] };
} catch (e) {
console.error("Error fetching article:", e);
error({ statusCode: 500, message: 'Server error' });
return { article: null };
}
}
,
methods: {
scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' });
},
toggleShareModal() {
this.showShareModal = !this.showShareModal;
},
},
data() {
return {
article: null,
showShareModal: false,
error: null
};}
}
</script>
This code does print ” no article found”
I can’t see the mistake. Can you help me please.