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

鸿蒙arkTs Toast抽取 及使用

Toast抽取,创建一个Utils

import promptAction from '@ohos.promptAction';
import display from '@ohos.display';
export function ToastUtils(msg:string){try {promptAction.showToast({message: msg,duration: 1500,bottom:450});} catch (error) {console.error(`showToast args error code is ${error.code}, message is ${error.message}`);};
}

  使用:

import promptAction from '@ohos.promptAction';
import { StringIsEmpty } from '../utils/StringUtils';
import { ToastUtils } from '../utils/ToastUtils';
@Entry
@Component
struct SubmitFormPage {@State message: string = 'Hello World'@State inputText: string = ""build() {Row() {Column({space:10}) {TextInput({ text: this.inputText, placeholder: '请输入名字' }).fontSize(15).fontWeight(FontWeight.Normal).width('100%').height(50).backgroundColor('#f6f6f6').borderRadius(10).onChange((value) => {this.inputText= value})Button("提交").height(50).width(100).backgroundColor(Color.Blue).alignSelf(ItemAlign.Center).onClick(()=>{let isEmpty = StringIsEmpty(this.inputText);if (isEmpty) {ToastUtils("请输入文字~")}else{ToastUtils(this.inputText)}})}.width('100%').justifyContent(FlexAlign.Center).alignItems(HorizontalAlign.Start)}.height('100%')}
}

stringUtils只是判断是否为空

export function StringIsEmpty(str:string){return str === null || str === undefined || str.trim().length === 0;
}
http://www.lryc.cn/news/260178.html

相关文章:

  • 网络安全渗透测试的相关理论和工具
  • C 语言 xml 库的使用
  • 群晖(Synology)云备份的方案是什么
  • Flask 中的跨域难题:定义、影响与解决方案深度解析
  • 汽车IVI中控开发入门及进阶(十二):V4L2视频
  • gitlab下载安装
  • Jmeter,提取响应体中的数据:正则表达式、Json提取器
  • 【SpringBoot篇】基于布隆过滤器,缓存空值,解决缓存穿透问题 (商铺查询时可用)
  • Gitlab基础篇: Gitlab docker 安装部署、Gitlab 设置账号密码
  • c++常见函数处理
  • MYsql第二次作业
  • SQLAlchemy 第三篇
  • 交互过程中影响信息质量好坏的因素
  • 服务器上配置jupyter,提示Invalid credentials如何解决
  • Axure中动态面板使用及轮播图多种登录方式左侧导航栏之案列
  • 大数据之旅-问题反思
  • 系统级基础信号知识【Linux】
  • Excel单元格隐藏如何取消?
  • Visual Studio(VS)常用快捷键(最详细)
  • UDP特性之组播(多播)
  • ElasticSearch之cat shards API
  • Thread-Per-Message设计模式
  • 运筹学经典问题(一):指派问题
  • 产品经理之如何编写竞品分析(医疗HIS系统管理详细案例模板)
  • 虚拟内存管理
  • ssh时怎么同时指定其端口号,以及scp文件到远程的指定端口
  • Redis过期淘汰策略
  • 微信小程序---自定义组件
  • CGAL的最优传输曲线重构
  • 使用Docker本地安装部署Draw.io绘图工具并实现远程访问协作办公