语法
值传递与引用字面量传递
值传递
myComponent(this.params)
@Builder function myComponent(params){ params }
|
引用字面量传递
引用字面量必须带"{}",且值传递无法让父组件的值刷新
myComponent({attr1:a1,attr2:a2})
@Builder function myComponent(params){ params.attr1 } export interface Params{ attr1:Attr1 attr2:Attr2 }
|
取反
doLike:(item:ReplyItemModel)=>void =(item: ReplyItemModel)=>{ }
|
传入匿名函数
类型断言
xx as Type data:GoodsModule=new GoodsModule({} as GoodsInfo)
|
对Object数组排序
if(sortMethod===true){ this.commentsInfoArr.sort((x:CommentsInfo,y:CommentsInfo)=> { if (x.date >y.date) { return -1; } if (x.date <y.date) { return 1; } return 0} ) }
|
对Object数组去重
let newCart:Foods[] = [] this.shoppingCartArr.forEach((item:Foods)=>{ return newCart.includes(item)?'':newCart.push(item) }) this.shoppingCartArr = newCart
|
日期格式化
@State now: Date = new Date() @State formattedDate: string = this.now.toLocaleDateString("en-US");
|
随机数
rnd = Math.random()*RANGE
|
时间相关
setTimeout
t时间后才执行
setInterval
每隔t时间执行一次
taskId:number = -1 this.taskId = setTnterval(()=>{ ++this.cnt clearInterval(this.taskId) },t)
|