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

后端 未结 3 2106
渐次进展
渐次进展 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:46

    I`m prefer call API in created hook. Quote from alligator.io:

    In the created hook, you will be able to access reactive data and events are active. Templates and Virtual DOM have not yet been mounted or rendered.

    So you easy can access to data to parse and save response from a server if you need.

    Regards.

提交回复
热议问题