I have the code below in the file _slug.vue
{{ feed }} always returns an empty array.
The console.log(this.feed) in the async fetch functions logs the correct data( an array of three objects) returned from the api call(a custom strapi controller). But again, feed is empty in the page itself.
{{ category }} is works as intended, both in the page and the console.log inside the async fetch function.
I have tried change the api call to one that does not require a param and that works in another page and I still get an empty array.
What am I missing?
<template>
<div>
<h1>Feed - {{ category }}</h1>
<p>{{ feed }}</p>
</div>
</template>
<script>
export default {
data() {
return {
feed: [],
category: this.$route.params.slug,
}
},
async fetch({ params }) {
const category = params.slug
console.log('slug: ' + category)
this.feed = await fetch(
`http://localhost:1337/api/getCategory/${params.slug}`
).then((res) => res.json())
console.log(this.feed)
},
}
</script>