[Front-end learning-Vue (6) In which life cycle is the asynchronous request suitable for calling? 】

1. In which life cycle is the asynchronous request suitable for invocation?

官方实例The asynchronous request is mountedcalled in the life cycle, but in fact it can also be called in the created life cycle.

I recommend calling asynchronous requests in the created hook function, which has the following advantages:

  • It can 更快be obtained 服务端数据, 减少page loading time;
  • ssrBeforeMount and mounted hook functions are not supported, so placing them in created will help consistency;


 

Guess you like

Origin blog.csdn.net/weixin_60364883/article/details/126715396