I am currently utilizing
asyncData
to fetch data from an API, however it is restricted to pages and cannot be used in components.- On the other hand, methods can be used in both pages and components.
As these two methods function similarly, I am considering using methods for fetching API data. This leads me to question if there are any significant differences between asyncData and method ?
export default {
async asyncData ({ req }) {
let { data } = await axios.get(process.env.API_SERVER + `/v1/projects`)
return { items: data }
},
data () {
return {
items: null
}
},
methods: {
async getItems () {
let { data } = await axios.get(process.env.API_SERVER + `/v1/projects`)
this.items = data
}
}