Vue.js - Which component lifecycle should be used for fetching data?

后端 未结 3 2111
渐次进展
渐次进展 2021-02-13 16:48

After reading one of Alligator.io posts about Vue that was saying that mounted lifecycle is a bad place to use http get. I was wondering if there are any guidelines to how prope

3条回答
  •  佛祖请我去吃肉
    2021-02-13 17:36

    The created() lifecycle hooks fullfills all requirements for fetching and processing API data.

    However the official Vue documentation uses the mounted() lifecycle hook in example code for integration API calls with axios: https://vuejs.org/v2/cookbook/using-axios-to-consume-apis.html

    Both lifecycle hooks mounted() and created() are widely used for fetching API data and considered as good practice.

提交回复
热议问题