设计原则,将对象传递给组件

时间:2021-09-01 14:12:30

I am designing a page that shows a list of people and it displays each person as a card. So I wanted to create a directive to handle that, to isolate the html code that shows one person in one directive. Since I already have the list and what's needed to show one person I wanted the directive to just receives an object that has the person's information and knows how to display that properly. My friends on the other hand think that each directive should just get the id of the person and call the server to get the information. What are your thoughts?

我正在设计一个显示人员列表的页面,它将每个人显示为一张卡片。所以我想创建一个指令来处理它,以隔离在一个指令中显示一个人的html代码。由于我已经有了列表以及显示一个人需要什么,我希望该指令只接收一个具有该人信息的对象并知道如何正确显示该对象。另一方面,我的朋友认为每个指令应该只获取人的id并调用服务器来获取信息。你怎么看?

1 个解决方案

#1


0  

Passing object to child component (or directive) is better choose. In this way child components are more reusable. This improves application scalability.

将对象传递给子组件(或指令)是更好的选择。通过这种方式,子组件更具可重用性。这提高了应用程序可伸缩性

Of course it depends of situation and application architecture but in most situations child components should be as simple as possible.

当然,这取决于情况和应用程序架构,但在大多数情况下,子组件应尽可能简单。

Maybe in other part of system you will load full list of people then pass each person to directive. It is single request to serwer instead of 20.

也许在系统的其他部分,您将加载完整的人员列表,然后将每个人传递给指令。这是对服务而不是20的单一要求。

#1


0  

Passing object to child component (or directive) is better choose. In this way child components are more reusable. This improves application scalability.

将对象传递给子组件(或指令)是更好的选择。通过这种方式,子组件更具可重用性。这提高了应用程序可伸缩性

Of course it depends of situation and application architecture but in most situations child components should be as simple as possible.

当然,这取决于情况和应用程序架构,但在大多数情况下,子组件应尽可能简单。

Maybe in other part of system you will load full list of people then pass each person to directive. It is single request to serwer instead of 20.

也许在系统的其他部分,您将加载完整的人员列表,然后将每个人传递给指令。这是对服务而不是20的单一要求。