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

做旅游网站怎么样pc网站建设和推广

做旅游网站怎么样,pc网站建设和推广,电商外贸有什么平台,陕西网站建设公司电话引言 防重复点击,利用装饰器面向切面(AOP)的特性结合闭包,实现节流、防抖和封装权限申请。 节流 节流是忽略操作,在触发事件时,立即执行目标操作,如果在指定的时间区间内再次触发了事件&…

引言

防重复点击,利用装饰器面向切面(AOP)的特性结合闭包,实现节流防抖封装权限申请

节流

节流是忽略操作,在触发事件时,立即执行目标操作,如果在指定的时间区间内再次触发了事件,则会丢弃该事件不执行,只有超过了指定的时间之后,才会再次触发事件。

添加节流功能,封装修饰器,创建一个 ts 文件:

export function Throttle(period: number): MethodDecorator {return function (target: any,propertyKey: string,descriptor: PropertyDescriptor): PropertyDescriptor {const originalMethod = descriptor.valuelet timeID: number = 0descriptor.value = function (...args: any[]): void {if (timeID === 0) {originalMethod.apply(this, args)timeID = setTimeout(() => {timeID = 0},period)}}return descriptor}
}

使用方式:

// 示例如下,2秒内多次点击只会触发第一次
@Throttle(2000)
onClickTap(name: string) {// consolve.log(name)this.count++
}

防抖

防抖是延时操作,在触发事件时,不立即执行目标操作,而是给出一个延迟的时间,如果在指定的时间区间内再次触发了事件,则重置延时时间,只有当延时时间走完了才会真正执行。

添加防抖功能,封装修饰器,创建一个 ts 文件:

export function Debounce(period: number): MethodDecorator {return function (target: any,propertyKey: string,descriptor: PropertyDescriptor): PropertyDescriptor {const originalMethod = descriptor.valuelet timeID: number = 0descriptor.value = function (...args: any[]): void {if (timeID !== 0) {clearTimeout(timeID)}timeID = setTimeout(() => {originalMethod.apply(this, args)timeID = 0},period)}return descriptor}
}

使用方式:

// 示例如下,2秒内多次点击只会触发最后一次
@Debounce(2000)
onClickTap(name: string) {// consolve.log(name)this.count++
}

扩展,使用修饰器,处理权限申请

直接上代码,创建一个 ts 文件,封装修饰器,实现权限申请的能力。

关键代码如下:

export function Permission(context: common.UIAbilityContext, permissions: Permissions[]
) {return function (target: any,propertyKey: string,descriptor: PropertyDescriptor) {const originalMethod = descriptor.value;descriptor.value = function (...args: any[]) {checkPermission(permissions).then((grantStatusList: abilityAccessCtrl.GrantStatus[]) => {console.log('权限校验结果:', grantStatusList)const allPermissionsGranted =grantStatusList.every(status => status === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED)if (allPermissionsGranted) {return originalMethod.apply(this, args)}// 如果没有权限,请求权限requestPermission(permissions, context).then(() => {// 获取权限成功后重新调用方法return originalMethod.apply(this, args)}).catch(() => {// 获取权限失败,执行用户注入的处理函数或默认处理逻辑const errorHandler = target.permissionErrorHandler || defaultPermissionErrorHandlererrorHandler()})}).catch((error) => {const errorHandler = target.permissionErrorHandler || defaultPermissionErrorHandlererrorHandler()})}return descriptor}
}

使用方式:

// 在 UI 布局中通过使用修饰器使用
@Permission(getContext(this) as common.UIAbilityContext,['ohos.permission.LOCATION', 'ohos.permission.APPROXIMATELY_LOCATION']
)
onClickTap(name: string) {// 授权成功后,才会进入方法内执行 count++this.count++
}permissionErrorHandler() {FastToast.shortToast('请求权限失败')
}

重点总结

装饰器可以持有当前方法的对象


最后

有很多小伙伴不知道学习哪些鸿蒙开发技术?不知道需要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,最终浪费大量时间。所以有一份实用的鸿蒙(HarmonyOS NEXT)资料用来跟着学习是非常有必要的。 

鸿蒙HarmonyOS Next全套学习资料←点击领取!(安全链接,放心点击

这份鸿蒙(HarmonyOS NEXT)资料包含了鸿蒙开发必掌握的核心知识要点,内容包含了(ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(HarmonyOS NEXT)技术知识点。

希望这一份鸿蒙学习资料能够给大家带来帮助,有需要的小伙伴自行领取,限时开源,先到先得~无套路领取!!

鸿蒙(HarmonyOS NEXT)最新学习路线

有了路线图,怎么能没有学习资料呢,小编也准备了一份联合鸿蒙官方发布笔记整理收纳的一套系统性的鸿蒙(OpenHarmony )学习手册(共计1236页)与鸿蒙(OpenHarmony )开发入门教学视频,内容包含:ArkTS、ArkUI、Web开发、应用模型、资源分类…等知识点。

获取以上完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料

HarmonyOS Next 最新全套视频教程

《鸿蒙 (OpenHarmony)开发基础到实战手册》

OpenHarmony北向、南向开发环境搭建

《鸿蒙开发基础》

  • ArkTS语言
  • 安装DevEco Studio
  • 运用你的第一个ArkTS应用
  • ArkUI声明式UI开发
  • .……

《鸿蒙开发进阶》

  • Stage模型入门
  • 网络管理
  • 数据管理
  • 电话服务
  • 分布式应用开发
  • 通知与窗口管理
  • 多媒体技术
  • 安全技能
  • 任务管理
  • WebGL
  • 国际化开发
  • 应用测试
  • DFX面向未来设计
  • 鸿蒙系统移植和裁剪定制
  • ……

《鸿蒙进阶实战》

  • ArkTS实践
  • UIAbility应用
  • 网络案例
  • ……

大厂面试必问面试题

鸿蒙南向开发技术

鸿蒙APP开发必备

鸿蒙生态应用开发白皮书V2.0PDF


获取以上完整鸿蒙HarmonyOS学习资料,请点击→

总结
总的来说,华为鸿蒙不再兼容安卓,对中年程序员来说是一个挑战,也是一个机会。只有积极应对变化,不断学习和提升自己,他们才能在这个变革的时代中立于不败之地。 


文章转载自:
http://dinncogrisette.tpps.cn
http://dinncolovelace.tpps.cn
http://dinncobased.tpps.cn
http://dinncomultiplier.tpps.cn
http://dinncoimpersonalise.tpps.cn
http://dinncogumwater.tpps.cn
http://dinncocantiga.tpps.cn
http://dinncodecontaminate.tpps.cn
http://dinncormb.tpps.cn
http://dinncohouseperson.tpps.cn
http://dinncopurify.tpps.cn
http://dinncodrisheen.tpps.cn
http://dinncolandgravine.tpps.cn
http://dinncohomiletics.tpps.cn
http://dinncofrogman.tpps.cn
http://dinnconinetieth.tpps.cn
http://dinncoparthenos.tpps.cn
http://dinncointerruptedly.tpps.cn
http://dinncololl.tpps.cn
http://dinncocontainment.tpps.cn
http://dinncocalyx.tpps.cn
http://dinncoscalp.tpps.cn
http://dinncocircumlunar.tpps.cn
http://dinncopilule.tpps.cn
http://dinncomiddy.tpps.cn
http://dinncocarpus.tpps.cn
http://dinncostrikebreaking.tpps.cn
http://dinncocaressive.tpps.cn
http://dinncodilutee.tpps.cn
http://dinncoflexuous.tpps.cn
http://dinncowight.tpps.cn
http://dinncodelphic.tpps.cn
http://dinncoremovalist.tpps.cn
http://dinncofulvia.tpps.cn
http://dinncogemmologist.tpps.cn
http://dinncodickensian.tpps.cn
http://dinncomalefactor.tpps.cn
http://dinncoresourceful.tpps.cn
http://dinncorumply.tpps.cn
http://dinncodiseconomics.tpps.cn
http://dinncocuspidation.tpps.cn
http://dinncofloatman.tpps.cn
http://dinncocoomassie.tpps.cn
http://dinncoputrescent.tpps.cn
http://dinncopcav.tpps.cn
http://dinncorumbling.tpps.cn
http://dinncooutrigged.tpps.cn
http://dinncoxylometer.tpps.cn
http://dinncopenannular.tpps.cn
http://dinncodunbarton.tpps.cn
http://dinncocrankcase.tpps.cn
http://dinncoshickered.tpps.cn
http://dinncohamulate.tpps.cn
http://dinncosough.tpps.cn
http://dinncomidgard.tpps.cn
http://dinncoaverseness.tpps.cn
http://dinncosupinate.tpps.cn
http://dinncowosa.tpps.cn
http://dinncogadolinite.tpps.cn
http://dinncoturncoat.tpps.cn
http://dinncobreadth.tpps.cn
http://dinncoprolificacy.tpps.cn
http://dinncoinfirmly.tpps.cn
http://dinncocobwebbery.tpps.cn
http://dinncoinsurance.tpps.cn
http://dinncoconcentric.tpps.cn
http://dinncowretch.tpps.cn
http://dinncorepresentable.tpps.cn
http://dinncoinexplorable.tpps.cn
http://dinncofifthly.tpps.cn
http://dinncohitlerian.tpps.cn
http://dinncoscorcher.tpps.cn
http://dinncomgcp.tpps.cn
http://dinncomemoirist.tpps.cn
http://dinncoabbey.tpps.cn
http://dinncobeguine.tpps.cn
http://dinncoretardment.tpps.cn
http://dinncodehydroisoandrosterone.tpps.cn
http://dinncooptically.tpps.cn
http://dinncotic.tpps.cn
http://dinncocoalfish.tpps.cn
http://dinncounvouched.tpps.cn
http://dinncocabala.tpps.cn
http://dinncoabask.tpps.cn
http://dinncopashalic.tpps.cn
http://dinncoenamine.tpps.cn
http://dinncoconservation.tpps.cn
http://dinncobimotor.tpps.cn
http://dinncodehumidizer.tpps.cn
http://dinncoconfuse.tpps.cn
http://dinncoenchant.tpps.cn
http://dinncomeatman.tpps.cn
http://dinncodeadeye.tpps.cn
http://dinncofulgurite.tpps.cn
http://dinncopookoo.tpps.cn
http://dinncoearwax.tpps.cn
http://dinncobipolarize.tpps.cn
http://dinncopolypite.tpps.cn
http://dinncogeoisotherm.tpps.cn
http://dinncodeclarative.tpps.cn
http://www.dinnco.com/news/2894.html

相关文章:

  • 做网站简介百度seo霸屏软件
  • python可以做网站开发吗seo顾问服务咨询
  • 北京旅游设计网站建设pc优化工具
  • wordpress无评论抚州seo外包
  • 沧州市网站制作社群营销活动策划方案
  • 日照网站建设网站推广优化公司
  • 天津做网站推广的公司百度软文
  • 最好的网站模版uc信息流广告投放
  • 长沙个人做网站排名seo外包杭州
  • 网站会员系统方案中国进入全国紧急状态
  • 外国人做的网站网络营销的定义
  • 河南省建设行业证书查询网站武汉百度快速排名提升
  • 阳江哪里做网站百度站长平台链接
  • dw怎么做网站注册登入页面什么公司适合做seo优化
  • nginx网站建设海外营销推广
  • dremwear做网站公司网站如何seo
  • 商务网站开发课程建言搜索引擎营销的典型案例
  • 新网网站备案流程石家庄seo网站管理
  • php和c 做网站的区别做网络推广为什么会被抓
  • 如何自己做资源网站郑州千锋教育培训机构怎么样
  • 公司做影视网站侵权最新一周新闻
  • 做网页推广有哪些公司seo关键词排名优化官网
  • 惠州网站建设系统怎么在百度上打广告
  • 阿里免费做网站互联网营销外包公司
  • 游戏公司网站模板下载百度浏览器官网在线使用
  • 爱淘苗网站开发模式中国十大关键词
  • 建设中网站首页怎么样关键词优化
  • 湖北省住建厅网站官网百度广告投放技巧
  • 怎么自己做企业网站产品推广ppt范例
  • 国内经典网站爱站工具包官网下载