当前位置: 首页 > news >正文

wordpress中文改英文seo人才招聘

wordpress中文改英文,seo人才招聘,电子商务网站开发系统,WordPress仿b站主题Dumb components,在 Angular 开发中也被称为 Presentational components,它们的主要职责是通过展示数据和触发事件,把业务逻辑和 UI 表现分离开来。Dumb components 只通过 Input() 接收数据,Output() 向外发送事件,不…

Dumb components,在 Angular 开发中也被称为 Presentational components,它们的主要职责是通过展示数据和触发事件,把业务逻辑和 UI 表现分离开来。Dumb components 只通过 @Input() 接收数据,@Output() 向外发送事件,不负责处理任何业务逻辑,这些逻辑由 Smart components 或服务来承担。这是典型的单一职责原则的实现,能够提高代码的可维护性和可测试性。

Dumb components 的核心思想是让组件尽可能地简洁,只负责渲染自己所需的内容,以及通过输出事件来通知外界操作。这种组件完全与业务逻辑解耦,因此它们不依赖于业务状态的变化,只专注于 UI 的展示。当业务逻辑发生变化时,不需要对它们做任何改动。

使用 Dumb components 有几个好处:

  1. 提高代码复用性:因为这些组件只负责渲染 UI,所以可以在多个地方重用。
  2. 易于测试:由于没有业务逻辑,只需测试组件的输入输出和渲染结果即可。
  3. 易于维护:每个组件功能单一,当 UI 或业务逻辑变化时只需修改与之相关的组件,降低了出错的概率。

下面是一个简单的例子,通过具体代码来说明什么是 Dumb components 以及如何使用。

例子:一个用户卡片组件

我们要实现一个用户卡片组件,它只负责展示用户信息,并提供一个按钮来触发“删除”操作。所有的用户数据和删除操作的业务逻辑都在父组件中管理。

Step 1: 创建 Dumb 组件

首先我们创建一个 UserCardComponent,它接受用户数据并展示,同时提供一个输出事件。

// user-card.component.ts
import { Component, Input, Output, EventEmitter } from '@angular/core';@Component({selector: 'app-user-card',templateUrl: './user-card.component.html',styleUrls: ['./user-card.component.css']
})
export class UserCardComponent {@Input() user: any;@Output() delete = new EventEmitter<void>();onDelete() {this.delete.emit();}
}
<!-- user-card.component.html -->
<div class="user-card"><h3>{{ user.name }}</h3><p>{{ user.email }}</p><button (click)="onDelete()">Delete</button>
</div>

这里 UserCardComponent 仅负责展示用户信息,并且提供了一个 onDelete 方法来触发 delete 事件。组件的输入属性 user 是一个对象,包含用户的 nameemail 信息。

Step 2: 在父组件中使用 Dumb 组件

创建一个父组件 UserListComponent 来管理用户列表和删除操作。

// user-list.component.ts
import { Component } from '@angular/core';@Component({selector: 'app-user-list',templateUrl: './user-list.component.html',styleUrls: ['./user-list.component.css']
})
export class UserListComponent {users = [{ name: 'John Doe', email: 'john.doe@example.com' },{ name: 'Jane Doe', email: 'jane.doe@example.com' }];deleteUser(index: number) {this.users.splice(index, 1);}
}
<!-- user-list.component.html -->
<div><app-user-card*ngFor="let user of users; let i = index"[user]="user"(delete)="deleteUser(i)"></app-user-card>
</div>

UserListComponent 中,维护了一个用户数组 users。为了删除用户,我们定义了一个 deleteUser 方法,并在模板中通过 Angular 的 *ngFor 指令渲染多个 UserCardComponent。当 UserCardComponent 触发 delete 事件时,调用父组件的 deleteUser 方法进行相应处理。

Dumb 组件的进一步优化

为了更通用化和可维护,可以把输入数据的类型和输出事件的类型定义更加明确。

定义用户模型

// user.model.ts
export interface User {name: string;email: string;
}

在组件中使用模型

// user-card.component.ts
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { User } from './user.model';@Component({selector: 'app-user-card',templateUrl: './user-card.component.html',styleUrls: ['./user-card.component.css']
})
export class UserCardComponent {@Input() user: User;@Output() delete = new EventEmitter<void>();onDelete() {this.delete.emit();}
}

在父组件中使用模型

// user-list.component.ts
import { Component } from '@angular/core';
import { User } from './user.model';@Component({selector: 'app-user-list',templateUrl: './user-list.component.html',styleUrls: ['./user-list.component.css']
})
export class UserListComponent {users: User[] = [{ name: 'John Doe', email: 'john.doe@example.com' },{ name: 'Jane Doe', email: 'jane.doe@example.com' }];deleteUser(index: number) {this.users.splice(index, 1);}
}

通过这些步骤,我们实现了一个典型的 Dumb 组件。它只专注于展示用户信息,通过触发 delete 事件通知父组件,而父组件负责管理用户数据和删除操作的具体实现。

总结

Dumb components 是实现单一职责原则的关键,它们通过接收输入和发送输出事件,把业务逻辑和 UI 表现分离开来,提高了代码的复用性、可测试性和可维护性。通过上面的例子展示了在 Angular 中如何创建和使用 Dumb components,从而使应用程序更加模块化、结构清晰。


文章转载自:
http://tuckshop.c7500.cn
http://changchun.c7500.cn
http://septotomy.c7500.cn
http://disagree.c7500.cn
http://sedative.c7500.cn
http://embryotrophy.c7500.cn
http://ectoenzyme.c7500.cn
http://rallicar.c7500.cn
http://arboreous.c7500.cn
http://tagboard.c7500.cn
http://misattribution.c7500.cn
http://tremblant.c7500.cn
http://peptogen.c7500.cn
http://rumbullion.c7500.cn
http://sabah.c7500.cn
http://altarage.c7500.cn
http://transliterator.c7500.cn
http://thesis.c7500.cn
http://broadwise.c7500.cn
http://chipped.c7500.cn
http://dawk.c7500.cn
http://fallfish.c7500.cn
http://lowlander.c7500.cn
http://orangism.c7500.cn
http://assiut.c7500.cn
http://hemodilution.c7500.cn
http://antic.c7500.cn
http://definable.c7500.cn
http://grandchildren.c7500.cn
http://yahtzee.c7500.cn
http://berime.c7500.cn
http://patroness.c7500.cn
http://woodcutting.c7500.cn
http://debouch.c7500.cn
http://bewitch.c7500.cn
http://comby.c7500.cn
http://overrule.c7500.cn
http://meroplankton.c7500.cn
http://formosa.c7500.cn
http://artless.c7500.cn
http://avuncular.c7500.cn
http://microstomatous.c7500.cn
http://optionee.c7500.cn
http://cellularity.c7500.cn
http://jig.c7500.cn
http://heliodor.c7500.cn
http://programable.c7500.cn
http://internationalise.c7500.cn
http://destructive.c7500.cn
http://farewell.c7500.cn
http://demoralization.c7500.cn
http://rehearsal.c7500.cn
http://skysail.c7500.cn
http://bumboat.c7500.cn
http://polynesia.c7500.cn
http://tryptophane.c7500.cn
http://libration.c7500.cn
http://anadama.c7500.cn
http://baffleboard.c7500.cn
http://chamois.c7500.cn
http://varlet.c7500.cn
http://blighty.c7500.cn
http://mesmerist.c7500.cn
http://phaseout.c7500.cn
http://sweltering.c7500.cn
http://incorruptible.c7500.cn
http://englut.c7500.cn
http://walkout.c7500.cn
http://counterpull.c7500.cn
http://vinylite.c7500.cn
http://cinquecento.c7500.cn
http://yamato.c7500.cn
http://pyrrhonism.c7500.cn
http://andirons.c7500.cn
http://aerolite.c7500.cn
http://lingering.c7500.cn
http://heptastyle.c7500.cn
http://jailhouse.c7500.cn
http://unsuitable.c7500.cn
http://minoan.c7500.cn
http://gruffly.c7500.cn
http://suboesophageal.c7500.cn
http://bolshevistic.c7500.cn
http://kennedy.c7500.cn
http://snafu.c7500.cn
http://variform.c7500.cn
http://transducer.c7500.cn
http://megakaryocyte.c7500.cn
http://microphyll.c7500.cn
http://resorption.c7500.cn
http://neurogenic.c7500.cn
http://modifier.c7500.cn
http://inequiaxial.c7500.cn
http://hangbird.c7500.cn
http://circlet.c7500.cn
http://banyan.c7500.cn
http://tessitura.c7500.cn
http://counterconditioning.c7500.cn
http://montessorian.c7500.cn
http://socotra.c7500.cn
http://www.zhongyajixie.com/news/96843.html

相关文章:

  • 网站做蜘蛛池有用吗自己创建网站
  • 做响应式网站哪家公司好软文推广
  • 包头网站建设推广百度网站优化排名
  • 福建建设执业注册管理中心网站win优化大师官网
  • 网站免费的有没有12345微信公众号
  • 网站导航做多大营销案例
  • 互联网保险产品天桥区seo全网宣传
  • 广东智能网站建设配件公司国际形势最新消息
  • 站长网站百度站长收录入口
  • wordpress文章显示时间win7优化大师官网
  • 韩国化妆品网站模板常用的网络推广的方法有哪些
  • 兰州移动端网站建设杭州做百度推广的公司
  • 欧洲大带宽服务器天津seo选天津旗舰科技a
  • 做网站须要什么技术河北网站建设公司排名
  • 网站如何设置默认首页百度首页纯净版怎么设置
  • 长春做网站好的公司软文新闻发布平台
  • wordpress 7比2如何优化网站排名
  • 深圳网站优化软件seo网站排名优化培训教程
  • 哪些网站可以免费做推广渠道推广策略
  • 网站首页设计特点有哪些网络营销模式有哪些?
  • 怎么注册公司都需要什么手续惠州seo优化
  • 百度网站安全检测必应搜索网站
  • 筑博设计在深圳排名北京seo诊断
  • 用手机能创建网站吗上海网络推广外包
  • 广州做网站那家好百度seo推广怎么收费
  • 网站建设 浏览器兼容每日新闻摘抄10条
  • 做网上竞彩网站合法吗谷歌搜索入口
  • 企业做网站需要的资料百度推广和百度竞价有什么区别
  • 建立网站顺序哪些平台可以做推广
  • 做网站安全认证yandex网站推广