Should the initialization of the vue component be called within the component or from the parent component?

  1. for example, there is a drop-down box component that needs to initialize its contents. There is an init method inside the component to get the content data.
Should

be called with $refs.xxx.init () on the parent component, or should the child component be called directly in created or mounted?
(if $refs.xxx.init () is called, you can know when the initialization ends with the parent component of the asynchronous function, and execute it directly in created, or you can let the parent component know that the initialization ends through the $emit custom event)

what are the advantages and disadvantages of the two?

  1. assume that in addition to the drop-down box component A, there is another B component in the parent component that also needs to be initialized. The parent component needs to wait for the two child components to be initialized for subsequent operations. If both An and B components are on the parent component (calling their respective init methods through $refs.xxx.init ()), it is easy to implement.

but if both are initialized on their respective created and thrown with $emit, how should the parent component tell that both child components are initialized?
(does the parent component define a counter to + 1 when an event is triggered? Then perform the follow-up operation at 2? )

I don"t know if there is something wrong with my way of thinking. Please correct


call

in the mounted in the subcomponent
Menu