网站建设新手教学视频,外包加工网下载,东莞工作招聘网,优化大师的功能有哪些黑马程序员鸿蒙4.0视频学习笔记#xff0c;供自己回顾使用。1.安装开发工具DevEco Studio
鸿蒙harmony开发文档指南
DevEco Studio下载地址 选择或者安装环境 选择和下载SDK 安装总览 编辑器界面
2.TypeScript语法
2.1变量声明
//string 、number、boolean、any、u…黑马程序员鸿蒙4.0视频学习笔记供自己回顾使用。1.安装开发工具DevEco Studio
鸿蒙harmony开发文档指南
DevEco Studio下载地址 选择或者安装环境 选择和下载SDK 安装总览 编辑器界面
2.TypeScript语法
2.1变量声明
//string 、number、boolean、any、union、Object、Array
let s: string hello world
const ss: string hello world//const 代表常量
//any,个人不建议使用代码量庞大后导致代码逻辑混乱
let a:any 不确定类型可能是任意类型
//union
let u:string|number|boolean 联合类型可能是其中一种
//Object,对象类型
let car {brand:问界,Price:199999}
console.log(car.brand)
console.log(car[brand])
//Array:数组
let cars: Arraystring [问界,阿维塔]
let price: number[] [199999,299999]
console.log(cars[0])
console.log(price[1])2.2条件控制
//在TypeScript中空字符串、数字0、null、undefined都被认为是false其它值则为true
//if-else,写吐了不想写
if(){}else{}
if(){}else if(){}else{}
//switch
let season:string 冬天
switch(season){case 春天:{console.log(你的笑容那么美恰好与春风撞了个满怀)break}case 夏天:{console.log(玫瑰到了花期我很想你)break}case 秋天:{console.log(盛夏欠你的温柔让秋风徐徐来还。)break}default{console.log(情话是学的但爱你是真的)break}
}2.3循环迭代
//for
for(let i 0;i100;i){console.log(拥有i个男女模对象)
}
// for-in
let cars: string[] [问界,阿维塔]
for(const i in cars){console.log(cars[i])
}
//for-of
for(const car of cars){console.log(car)
}
//while
let i 1;
while(i 100){console.log(拥有i个男女模对象)i;
}2.4函数
//无返回值
function func1(car:string):void{console.log(car)
}
fun1(问界)
//有返回值
function func2(x: number,y:number):number{return xy
}
let count func2(1,1)
console.log(113?11count)
//简写版箭头函数
let func3 (car:string) {console.log(car)
}
func3(阿维塔)
//函数可选参数
function func4(car?:string){car car?car:哦莫console.log(car)
}
func4()
func4(link)
//函数可选参数,提供默认值
function func5(car:string哦莫){console.log(car)
}
func5()
func5(link)2.5类和接口
//定义枚举
enum GamesConsole{SWITCH:1999,PS5:2999,XBOXONE:2999
}
//定义接口抽象方法接受枚举参数
interface Price{//类和对象里的函数不需要加functionshowPS5Price(price:GamesConsole):void
}
//实现接口
class Article implements Price{showPS5Price(price:GamesConsole):void{console.log(ps5的价格是price)}
}
//初始化对象
let p:Price new Article()
//调用方法传递枚举参数
p.showPrice(GamesConsole.PS5)//父类
class Rectangle{//成员变量private width:numberprivate length:number//构造函数constructor(width:number,length:number){this.widthwidththis.lengthlength}//成员方法public area():number{return this.width * this.length}
}
//子类
class Square extends Rectangle{constructor(side:number){//调用父类构造super(side,side)}
}let s new Square(10)
console.log(s.area())2.6模块开发
通用功能抽取到单独的ts文件每个文件都是一个模块(module)。 模块可以相互加载提高代码复用性。
//rectangle.ts
//定义类通过export导出
export class Rectangle{//成员变量private width:numberprivate length:number//构造函数constructor(width:number,length:number){this.widthwidththis.lengthlength}
}
//定义工具方法通过export导出
export function area(rec:Rectangle):number{return rec.width * rec.length
}//index.ts
//通过import导入from后面写文件的地址
import {Rectangle,area} from ../rectangle//创建Rectangle对象
let r new Rectangle(10,10)//调用area方法
console.log(面积为area(r))3.快速入门-hello world
create project - empty ability Index.ets文件解读
Entry
Component
struct Index {State message: string Hello Worldbuild() {Row() {Column() {Text(this.message).fontSize(50).fontWeight(FontWeight.Bold).onClick((){//...处理事件if (this.message Hello World) {this.message 你好 世界}else {this.message Hello World}})}.width(100%)}.height(100%)}
}4.ArkUI组件
4.1Image组件
Image:图片显示组件
1.声明Image组件并设置图片源:
Image(src: string|PixelMap|Resource)① string格式通常用来加载网络图片需要申请网络访问权限: ohos.permission.INTERNET
Image(https://xxx . png )② PixelMap格式可以加载像素图常用在图片编辑中
Image(PixelMapObeject)③ Resource格式加载本地图片推荐使用
Image($r(app.media.mate60))
Image($rawfile(mate60.png))2.添加图片属性
Image($r(app .media.icon)).width(100) //宽度.height(120) //高度.borderRadius(10) // 边框圆角.interpolation(ImageInterpolation.High) // 图片插值4.2Text组件
Text:文本显示组件 1.声明Text组件并设置文本内容
Text(content?:string|Resource)①string格式直接填写文本内容
Text(今天天气很好呀)②Resource格式读取本地资源文件
Text($r(app.string.hello))2。添加文本属性
Text(注册账号).lineHeight(32) // 行高.fontSize(20) // 字体大小.fontColor(#ff1876f8) // 字体颜色.fontWeight(FontWeight.Medium) // 字体粗细4.3TextInput组件
TextInput文本输入框 1.声明TextInput组件
TextInput( {placeholder?: ResourceStr,text?: ResourceStr})①placeHoder:输入框无输入时的提示文本
TextInput([placeholder:请输入账号或手机号})②text: 输入框当前的文本内容
TextInput({text: 1234567890})2.添加属性和事件
TextInput({text:当前输入文本).width(150) //宽.height(30) // 高.backgroundColor(#FFF) // 背景色.type(InputType.Password)//输入框类型.onChange(value{//value是用户输入的文本内容})名称描述Normal基本输入模式。支持输入数字、字母、下划线、空格、特殊字符。Password密码输入模式。支持输入数字、字母、下划线、空格、特殊字符。Email邮箱地址输入模式。支持数字字母下划线以及字符。Number纯数字输入模式。PhoneNumber9电话号码输入模式。支持输入数字、、-、*、长度不限。
4.4 Button组件
Button按钮组件 1.声明Button组件label是按钮文字
Button(label?:ResourceStr)① 文字型按钮
Button(点我)② 自定义按钮在Button内嵌套其它组件
Button(){Image($r(app.media.search)).width(20).margin(10)
}2.添加属性和事件
Button(点我).width(100).height(30).type(ButtonType.Normal)//按钮类型.onclick((){//处理点击事件})4.5 Slider组件
Slider:滑动条组件
Slider(options?:SliderOptions)Slider({min:0,//最小值max:100,//最大值value:30,//当前值step:10,//滑动步长style:SliderStyle.OutSet,//Insetdirection:Axis.Horizontal,//Verticalreverse:false//是否反向滑动
}).width(90%).showTips(true)//是否展示value百分比提示.blockColor(#36D).onChangge(value{//value就是当前滑块值})4.6 Column和Row
属性方法名说明参数justifyContent设置子元素在主轴方向的对其格式FlexAlign枚举alignItems设置子元素在交叉轴方向的对其格式Row容器使用VerticalAlign枚举alignItems设置子元素在交叉轴方向的对其格式Column容器使用HorizontalAlign枚举
FlexAlign枚举:FlexAlign.StartFlexAlign.CenterFlexAlign.EndFlexAlign.SpaceBetweenFlexAlign.SpaceAroundFlexAlign.SpaceEvenlyHorizontalAlign枚举HorizontalAlign.StartHorizontalAlign.CenterHorizontalAlign.EndVerticalAlign枚举VerticalAlign.startVerticalAlign.CenterVerticalAlign.End4.7 循环控制
ForEachif-else
4.8 List
列表(List)是一种复杂容器具备以下特点 ① 列表项(ListItem)数量过多超出屏幕后会自动提供滚动功能 ②列表项(ListItem)既可以纵向排列也可以横向排列
List({space:10}){ForEach([1,2,3,4],item {ListItem(){//列表项内容只能包含一个根组件Text(ListItem)}})
}
.width(100%)4.9 自定义组件
创建自定义组件BuiderStyles
Buider style Extend不仅可以写特有属性方法还可以写事件方法
5 ArkUI-状态管理
5.1State装饰器
在声明式UI中是以状态驱动视图更新 状态state指驱动视图更新的数据被装饰器标记的变量 视图View基于UI描述渲染得到用户界面
Entry
Component
struct Index {State message: string Hello Worldbuild() {Text(this.message).onClick((){this.message Hello World?this.message 你好 世界:this.message Hello World})}}说明
State装饰器标记的变量必须初始化不能为空值。
State支持Object、class、string、number、boolean、enum类型已经这些类型的数组。
嵌套类型以及数组中的对象属性无法触发视图更新。如果做过vue开发应该很好理解。
下个目录所需要的案例
// 任务类
class Task{static id:number 1// 任务名称name:string 任务${Task.id}// 任务状态是否完成finished:boolean false
}
// 统一的卡片样式
Styles function card(){.width(95%).padding(20).backgroundColor(Color.White).borderRadius(15).shadow({radius:6,color:#1F000000,offsetX:2,offsetY:4})
}
// 任务完成样式
Extend(Text) function finishedTask(){.decoration({type:TextDecorationType.LineThrough}).fontColor(#B1B2B1)
}Entry
Component
struct PropPage {State message: string Hello World// 总任务数量State totalTask:number 0// 已完成任务数量State finishTask:number 0// 任务数组State tasks:Task[] []handleTaskChange(){// 更新任务总数量this.totalTask this.tasks.length// 更新已完成任务数量this.finishTask this.tasks.filter(item item.finished).length}build() {Column({space:10}) {// 任务进度卡片Row(){Text(任务进度).fontSize(30).fontWeight(FontWeight.Bold)// 层叠容器Stack(){Progress({value:this.finishTask,total:this.totalTask,type:ProgressType.Ring}).width(100)Row(){Text(this.finishTask.toString()).fontColor(#36D).fontSize(24)Text( / this.totalTask.toString()).fontSize(24)}}}.card().margin({top:20,bottom:10}).justifyContent(FlexAlign.SpaceEvenly)// 新增任务按钮Button(新增任务).width(200).onClick((){this.tasks.push(new Task())// 更新任务总数量// this.totalTask this.tasks.lengththis.handleTaskChange()})// 任务列表// 任务列表List版本List({space:10}){ForEach(this.tasks,(item:Task,index) {ListItem(){Row(){Text(item.name).fontSize(20)Checkbox().select(item.finished).onChange(val{// 更新当前任务状态item.finished val// 更新已完成任务数量// this.finishTask this.tasks.filter(item item.finished).lengththis.handleTaskChange()})}.card().justifyContent(FlexAlign.SpaceBetween)}.swipeAction({end:this.DeleteButton(index)})})}.width(100%).alignListItem(ListItemAlign.Center).layoutWeight(1)}.width(100%).height(100%).backgroundColor(#F1F2F3)}Builder DeleteButton(index: number){Button(){Image($r(app.media.ic_public_delete_filled)).fillColor(Color.White).width(20)}.width(40).height(40).type(ButtonType.Circle).backgroundColor(Color.Red).margin(5).onClick((){this.tasks.splice(index,1)this.handleTaskChange()})}
}5.2 Prop和Link
状态管理 当父子组件之间需要数据同步时可以使用Prop和Link装饰器
PropLink同步类型单向同步双向同步允许修饰的变量类型1. Prop只支持string、number、boolean、enum类型 。2.父组件对象类型子组件对象属性。3.不可以是数组、any1.父子类型一致string、number、boolean、enum、object、class以及他们的数组。2.数组中元素增、删、替换会引起刷新。 3.嵌套类型以及数组中的对象属性无法触发视图更新初始化方式不允许子组件初始化父组件传递禁止子组件初始化 // 任务类
class Task{static id:number 1// 任务名称name:string 任务${Task.id}// 任务状态是否完成finished:boolean false
}
// 统一的卡片样式
Styles function card(){.width(95%).padding(20).backgroundColor(Color.White).borderRadius(15).shadow({radius:6,color:#1F000000,offsetX:2,offsetY:4})
}
// 任务完成样式
Extend(Text) function finishedTask(){.decoration({type:TextDecorationType.LineThrough}).fontColor(#B1B2B1)
}Entry
Component
struct PropPage {State message: string Hello World// 总任务数量State totalTask:number 0// 已完成任务数量State finishTask:number 0build() {Column({space:10}) {// 任务进度卡片TaskStatistics({finishTask:this.finishTask,totalTask:this.totalTask})// 任务列表TaskList({finishTask:$finishTask,totalTask:$totalTask})}.width(100%).height(100%).backgroundColor(#F1F2F3)}}Component
struct TaskStatistics {Prop finishTask:numberProp totalTask:numberbuild(){Row(){Text(任务进度).fontSize(30).fontWeight(FontWeight.Bold)// 层叠容器Stack(){Progress({value:this.finishTask,total:this.totalTask,type:ProgressType.Ring}).width(100)Row(){Text(this.finishTask.toString()).fontColor(#36D).fontSize(24)Text( / this.totalTask.toString()).fontSize(24)}}}.card().margin({top:20,bottom:10}).justifyContent(FlexAlign.SpaceEvenly)}
}Component
struct TaskList {Link finishTask:numberLink totalTask:number// 任务数组State tasks:Task[] []handleTaskChange(){// 更新任务总数量this.totalTask this.tasks.length// 更新已完成任务数量this.finishTask this.tasks.filter(item item.finished).length}build(){Column(){// 新增任务按钮Button(新增任务).width(200).onClick((){this.tasks.push(new Task())// 更新任务总数量// this.totalTask this.tasks.lengththis.handleTaskChange()}).margin({bottom:10})// 任务列表List版本List({space:10}){ForEach(this.tasks,(item:Task,index) {ListItem(){Row(){Text(item.name).fontSize(20)Checkbox().select(item.finished).onChange(val{// 更新当前任务状态item.finished val// 更新已完成任务数量// this.finishTask this.tasks.filter(item item.finished).lengththis.handleTaskChange()})}.card().justifyContent(FlexAlign.SpaceBetween)}.swipeAction({end:this.DeleteButton(index)})})}.width(100%).alignListItem(ListItemAlign.Center).layoutWeight(1)}}Builder DeleteButton(index: number){Button(){Image($r(app.media.ic_public_delete_filled)).fillColor(Color.White).width(20)}.width(40).height(40).type(ButtonType.Circle).backgroundColor(Color.Red).margin(5).onClick((){this.tasks.splice(index,1)this.handleTaskChange()})}
}5.3 Provide和Consume
5.4 Observed和ObjectLink 文章转载自: http://www.morning.fwmln.cn.gov.cn.fwmln.cn http://www.morning.sqqds.cn.gov.cn.sqqds.cn http://www.morning.wtrjq.cn.gov.cn.wtrjq.cn http://www.morning.zlzpz.cn.gov.cn.zlzpz.cn http://www.morning.trhrk.cn.gov.cn.trhrk.cn http://www.morning.xkzmz.cn.gov.cn.xkzmz.cn http://www.morning.nfmlt.cn.gov.cn.nfmlt.cn http://www.morning.pwggd.cn.gov.cn.pwggd.cn http://www.morning.pigcamp.com.gov.cn.pigcamp.com http://www.morning.xxwl1.com.gov.cn.xxwl1.com http://www.morning.fdwlg.cn.gov.cn.fdwlg.cn http://www.morning.rfbq.cn.gov.cn.rfbq.cn http://www.morning.hrtwt.cn.gov.cn.hrtwt.cn http://www.morning.xhddb.cn.gov.cn.xhddb.cn http://www.morning.jkzq.cn.gov.cn.jkzq.cn http://www.morning.jmnfh.cn.gov.cn.jmnfh.cn http://www.morning.jgcyn.cn.gov.cn.jgcyn.cn http://www.morning.mzmqg.cn.gov.cn.mzmqg.cn http://www.morning.fmry.cn.gov.cn.fmry.cn http://www.morning.ykbgs.cn.gov.cn.ykbgs.cn http://www.morning.csnmd.cn.gov.cn.csnmd.cn http://www.morning.nfgbf.cn.gov.cn.nfgbf.cn http://www.morning.qrzqd.cn.gov.cn.qrzqd.cn http://www.morning.wmfmj.cn.gov.cn.wmfmj.cn http://www.morning.rklgm.cn.gov.cn.rklgm.cn http://www.morning.yxnfd.cn.gov.cn.yxnfd.cn http://www.morning.tdxnz.cn.gov.cn.tdxnz.cn http://www.morning.zlfxp.cn.gov.cn.zlfxp.cn http://www.morning.xblrq.cn.gov.cn.xblrq.cn http://www.morning.kndst.cn.gov.cn.kndst.cn http://www.morning.pwghp.cn.gov.cn.pwghp.cn http://www.morning.zdqsc.cn.gov.cn.zdqsc.cn http://www.morning.kdrly.cn.gov.cn.kdrly.cn http://www.morning.xqgh.cn.gov.cn.xqgh.cn http://www.morning.kxbry.cn.gov.cn.kxbry.cn http://www.morning.tqbqb.cn.gov.cn.tqbqb.cn http://www.morning.rtlrz.cn.gov.cn.rtlrz.cn http://www.morning.jwsrp.cn.gov.cn.jwsrp.cn http://www.morning.fbrshjf.com.gov.cn.fbrshjf.com http://www.morning.rbmnq.cn.gov.cn.rbmnq.cn http://www.morning.lfcfn.cn.gov.cn.lfcfn.cn http://www.morning.qkzdc.cn.gov.cn.qkzdc.cn http://www.morning.ysbhj.cn.gov.cn.ysbhj.cn http://www.morning.hwtb.cn.gov.cn.hwtb.cn http://www.morning.llgpk.cn.gov.cn.llgpk.cn http://www.morning.jyznn.cn.gov.cn.jyznn.cn http://www.morning.kpygy.cn.gov.cn.kpygy.cn http://www.morning.ypdmr.cn.gov.cn.ypdmr.cn http://www.morning.xq3nk42mvv.cn.gov.cn.xq3nk42mvv.cn http://www.morning.qkdcb.cn.gov.cn.qkdcb.cn http://www.morning.jpnw.cn.gov.cn.jpnw.cn http://www.morning.bkwd.cn.gov.cn.bkwd.cn http://www.morning.qcygd.cn.gov.cn.qcygd.cn http://www.morning.rcbdn.cn.gov.cn.rcbdn.cn http://www.morning.njfgl.cn.gov.cn.njfgl.cn http://www.morning.wqbrg.cn.gov.cn.wqbrg.cn http://www.morning.jqwpw.cn.gov.cn.jqwpw.cn http://www.morning.sdkaiyu.com.gov.cn.sdkaiyu.com http://www.morning.fcqlt.cn.gov.cn.fcqlt.cn http://www.morning.jhxdj.cn.gov.cn.jhxdj.cn http://www.morning.lbhck.cn.gov.cn.lbhck.cn http://www.morning.fldrg.cn.gov.cn.fldrg.cn http://www.morning.kdldx.cn.gov.cn.kdldx.cn http://www.morning.gccdr.cn.gov.cn.gccdr.cn http://www.morning.skkmz.cn.gov.cn.skkmz.cn http://www.morning.chmcq.cn.gov.cn.chmcq.cn http://www.morning.rbkl.cn.gov.cn.rbkl.cn http://www.morning.gxwyr.cn.gov.cn.gxwyr.cn http://www.morning.mhnd.cn.gov.cn.mhnd.cn http://www.morning.yrgb.cn.gov.cn.yrgb.cn http://www.morning.gbqgr.cn.gov.cn.gbqgr.cn http://www.morning.lwtfx.cn.gov.cn.lwtfx.cn http://www.morning.enjoinfo.cn.gov.cn.enjoinfo.cn http://www.morning.kltmt.cn.gov.cn.kltmt.cn http://www.morning.kdnrc.cn.gov.cn.kdnrc.cn http://www.morning.clwhf.cn.gov.cn.clwhf.cn http://www.morning.bjjrtcsl.com.gov.cn.bjjrtcsl.com http://www.morning.lrwsk.cn.gov.cn.lrwsk.cn http://www.morning.ncqzb.cn.gov.cn.ncqzb.cn http://www.morning.kpzrf.cn.gov.cn.kpzrf.cn