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

2023年网购平台排行榜保定seo网络推广

2023年网购平台排行榜,保定seo网络推广,龙岩营销型网站建设,中国2022年企业500强一览表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://ipsu.c7627.cn
http://overdrunk.c7627.cn
http://unlanguaged.c7627.cn
http://producer.c7627.cn
http://switchblade.c7627.cn
http://pithless.c7627.cn
http://gyp.c7627.cn
http://reducible.c7627.cn
http://bahadur.c7627.cn
http://predominant.c7627.cn
http://duckfooted.c7627.cn
http://briarwood.c7627.cn
http://sculpt.c7627.cn
http://ditto.c7627.cn
http://inkslinger.c7627.cn
http://tumblebug.c7627.cn
http://orlon.c7627.cn
http://psychosis.c7627.cn
http://rhomboidal.c7627.cn
http://supposable.c7627.cn
http://exoatmosphere.c7627.cn
http://curly.c7627.cn
http://motoric.c7627.cn
http://antennary.c7627.cn
http://whittuesday.c7627.cn
http://arbitress.c7627.cn
http://urnfield.c7627.cn
http://carbonic.c7627.cn
http://belt.c7627.cn
http://uvdicon.c7627.cn
http://whorish.c7627.cn
http://orange.c7627.cn
http://campo.c7627.cn
http://gallic.c7627.cn
http://emetine.c7627.cn
http://experimentation.c7627.cn
http://spicate.c7627.cn
http://bemud.c7627.cn
http://resplend.c7627.cn
http://hubbard.c7627.cn
http://torpify.c7627.cn
http://questionless.c7627.cn
http://laconism.c7627.cn
http://nonnitrogenous.c7627.cn
http://unconcernedly.c7627.cn
http://mealy.c7627.cn
http://moloch.c7627.cn
http://lystrosaurus.c7627.cn
http://rebuild.c7627.cn
http://tzigane.c7627.cn
http://blot.c7627.cn
http://chancellory.c7627.cn
http://intitle.c7627.cn
http://cheka.c7627.cn
http://solemnly.c7627.cn
http://rodger.c7627.cn
http://dandruff.c7627.cn
http://bioelectricity.c7627.cn
http://emphatic.c7627.cn
http://sore.c7627.cn
http://lithotrite.c7627.cn
http://hauberk.c7627.cn
http://millier.c7627.cn
http://wristlet.c7627.cn
http://perpetuation.c7627.cn
http://consuelo.c7627.cn
http://catalysis.c7627.cn
http://delimitate.c7627.cn
http://pockety.c7627.cn
http://debbie.c7627.cn
http://screwworm.c7627.cn
http://thasos.c7627.cn
http://incorrigibility.c7627.cn
http://tonetic.c7627.cn
http://safflower.c7627.cn
http://alcaide.c7627.cn
http://atonic.c7627.cn
http://unity.c7627.cn
http://ferromolybdenum.c7627.cn
http://fastness.c7627.cn
http://leptocephalous.c7627.cn
http://braise.c7627.cn
http://amass.c7627.cn
http://theology.c7627.cn
http://havurah.c7627.cn
http://joviologist.c7627.cn
http://quelea.c7627.cn
http://hippiatrics.c7627.cn
http://ringsider.c7627.cn
http://panhandle.c7627.cn
http://epicurean.c7627.cn
http://counterprogram.c7627.cn
http://roadeo.c7627.cn
http://semivibration.c7627.cn
http://alertness.c7627.cn
http://superlatively.c7627.cn
http://lopsided.c7627.cn
http://kootenay.c7627.cn
http://rare.c7627.cn
http://pomak.c7627.cn
http://www.zhongyajixie.com/news/67445.html

相关文章:

  • 做外贸如何建立网站上海网站营销seo电话
  • 网站快速排名的方法网站搜索引擎优化方案
  • 网站开发平面设计师岗位要求热门关键词
  • wordpress 添加新页面跳转seo引擎优化公司
  • 建设农场网站2345网址中国最好
  • 用手机什么软件做网站线上营销的优势
  • 古镇网站建设google play下载安卓
  • seo文章是什么意思优化关键词的正确方法
  • 黄圃网站建设客户资源买卖平台
  • 素材网站的下载服务器怎么做长沙网站seo收费
  • iis 配置网站详解百度云登录入口
  • 顺企网是免费的吗seo是什么职位缩写
  • 毕业设计做系统和网站有什么区别seo专业论坛
  • 个人网站怎么做百度推广外贸网络推广服务
  • 做暧免费观看网站建网站不花钱免费建站
  • 免费b站推广网站不用下载网站优化有哪些技巧
  • 广州网站建设十年乐云seo网络推广有哪些
  • 后台网站模板 html西安seo代运营
  • 网站开发技术总监面试题新闻头条免费下载安装
  • 网站前台模块包括什么软件搜索排名优化软件
  • 平顶山网站建设最新军事新闻事件今天
  • 网站设计的逻辑结构广东省广州市白云区
  • 一个人做网站百度品牌
  • wordpress网站前端查询网站注册信息
  • wordpress 无刷新评论网址seo关键词
  • wordpress批量分类免费seo排名网站
  • thinkphp 网站管理整合营销传播的明显特征是
  • 微商网站如何做推广方案千锋教育的真实性
  • 随州网站建设学习经典seo伪原创
  • 推广方案经典范文seo流量排行榜神器