export default {
data() {
return {
posts: []
};
},
async fetch() {
this.posts = await this.$axios.$get('https://api.example.com/posts');
},
fetchOnServer: false, // Only fetches on client-side navigation
// You can also control when to fetch data with a watchEffect
watchQuery: ['page'],
}
<template>
<div>
<div v-if="fetchState.pending">Loading...</div>
<div v-if="fetchState.error">Error! {{ fetchState.error.message }}</div>
<ul v-else>
<li v-for="post in posts" :key="post.id">{{ post.title }}</li>
</ul>
</div>
</template>