On the question of whether the data is really obtained in the parent component or in the child component

1. If you now have one parent component and three child components. The data displayed by each component is different, and
now has two ways to get the data.
the first is to get all the data in the parent component and pass it to each child component using props.
the second: get their own data in each subcomponent. ,
which one do you think is better? Why?

Mar.30,2021

according to the actual business

if the data is not needed by other components, it can be obtained by the child component itself
if the data may be reused and shared by the peer component, then it can be uniformly obtained by the parent component and then distributed
if the data may be reused and shared by cross-level components, then you need vuex or eventshub to be uniformly distributed to different levels of components


if the reuse rate of sub-components is high or the coupling is small, the data can be obtained independently

if the child component is closely related to the parent component, the parent component acquires data

A single request for data by a parent component saves network requests than a child component acquires data multiple times separately

according to the main idea of the subject, it should be that the parent component has a greater relationship with the child component. It is recommended that the parent component obtain the data


if the data of each component is not related, the second is adopted, otherwise the first

is adopted.
Menu