1. Toast
prompt.showToast({message: '上传失败', duration: 2000})
2. 定时循环处理
this.mInterValId = setInterval(()=>{ this.tcpSendData(this.mTcp, tcpSendOptions); },10000); clearInterval(this.mInterValId); // 终止
3. Image
Image($r('app.media.app_icon')) // 资源图片
.fontColor($r('app.color.blue')) // 颜色资源
4. page之间的参数传递, boolean直接传是可以的,string要封装对象
export class RouterParams { str:string bool:boolean constructor(str:string,,bool:boolean) { this.str = str this.bool = bool; } } // 发送 let options:router.RouterOptions = { url: 'pages/page1', params: new RouterParams(path,md5,true) } router.pushUrl(options);
// 收取
aboutToAppear() { if (router.getParams()) { let param:RouterParams = router.getParams() as RouterParams; this.mPath = param.str as string; this.mBool = param.bool; } }
5. 数组遍历
aArray.forEach((bean, index,array)=>{ this.mBeanList.add(bean); })
6. 取当前时间
const time1 = new Date().getTime(); // ms
const time2 = new Date().getTime();
const deltaTime = time2 - time1;
7. 字符串用变量
Text(`${va1}`) //注意这里不是引号,是1左边的分隔号
8. string 转 uint8array, 即string转bytearray
import { util } from '@kit.ArkTS'; let textEncoder = util.TextEncoder.create('utf-8'); let fileMd5Buff:Uint8Array = textEncoder.encodeInto(this.mPlayListMD5);
8. uint8array截取一部分转通用类型 , 即string转bytearray
// 用于操作 ArrayBuffer 和 string 互转 let textDecoder = util.TextDecoder.create('utf-8'); let data:ArrayBuffer = messageInfo.message; let devIdBuffer:ArrayBuffer = data.slice(17, 17 + devIdLen); deviceBean.deviceId = textDecoder.decodeWithStream(new Uint8Array(devIdBuffer));
9. 创建字节数组
dataPkg():Uint8Array{ let data:Uint8Array = new Uint8Array(14); data[0] = 0x00; return data; }
Ability Kit简介-Ability Kit(程序框架服务)-应用框架 | 华为开发者联盟 (huawei.com)