TYUT太原理工移动框架技术期末预测

没有基础的建议先看一下视频(真不是广告,这个快速入门真的挺好的)哪怕只看基础语法都行,看了之后看文章就没那么吃力了,然后记代码、看ppt、看老师发的那两个认证题库就ok了。如果你把实验全写过一遍,那基本上是没什么问题的。

题型我不知道,重点老师也几乎没说什么,如果有知道的同学可以发在评论区。

因为不知道题型所以我只能预测一些大概率会考的。


利用Router在不同页面中跳转(重点)

一般是嵌在按钮的点击事件里

//A.ets
Button('登录')
           //点击时间
          .onClick(()=>{
           //push或pushUrl都可以,现在用pushUrl,但是ppt上还是push
              router.push({
                //url就是你要跳转的页面路径
                url:'pages/B',
                //params携带你要传递的参数,用键值对保存数据
                params:{
                  name:this.name,
                  number:this.number
                },
              })
          })
//B.ets

//接受A传递过来的参数
    @State name: string = router.getParams()['name']
    @State number: number = router.getParams()['number']

//返回A
Button('返回')
          .onClick(()=>{
            router.back({
              url:'pages/A',
              params:{
                name:this.name,
                number:this.number
              },
            })
          })

UIAbility间的跳转(重点)

比较像安卓的Activity跳转

//获取当前context
  let context = getContext(this) as common.UIAbilityContext;

//设置want对象
let want:Want ={
    bundleName:'com.example.demo1',
    abilityName:'EntryAbility',
    parameters:{
      name :'111'
    }

  }

 context.startAbility(want)


 
const KEY: string = 'message'; 
//onCreate()方法中通过AppStorage存储want对象。 
onCreate(want, launchParam) { 
//获取want传过来的参数 
let warn : string = want?.parameters?.warnContext; 
//通过AppStorage 的SetOrCreate 存储 want 对象 
AppStorage.SetOrCreate(KEY,warn) 
hilog.info(0x0000, 'RegisterAbility', '%{public}s', 'Ability 
onCreate');
@State message:string = AppStorage.Get('message')

各种装饰器P211

重要的有@state、@prop、@link、@consume、@provide、@observed、@objectlink、@component、@builder、@extend、@styles


声明式开发范式组件

通用事件

通用事件是可以在任何组件上绑定的事件

onClick

伟大无需多言

Button('注册')
       
          .onClick(()=>{

            turnToRegister()

          })

通用属性

Button(item.componentName)
                    .width (' 100%')
                    .height (56)
                    .backgroundColor(0xFFFFFF)
                    .fontColor('rgb(0, 0, 0)')
                    .margin({top:30,bottom:30})
                    .padding({left:30,right:30})
                    //要注意的是这个圆形边框,实验里见了很多次
                    .borderRadius(10)

Text('message')
    .fontSize(24)
    .fontColor(Color.red)


Row(){
Button('1')
Text('3')
}
     .alignItems(HorizontalAlign.Center)
     .justifyContent(FlexAlign.Center)

这些就不多说了

接下来就是10个基础组件、9个容器组件、1个媒体组件、6个弹窗

基础组件

CheckBox

复选框

CheckboxGroup({group:'checkGroup'})

Checkbox({name:'check1',group:'checkGroup'})
            .select(true)

Radio

单选框

 Radio({value:'1',group:'RadioGroup'})
      
 Radio({value:'2',group:'RadioGroup'}).checked(true)

Button

button要注意的只有他的类型:Normal、Capsule、Circle

 Button('1',{type:ButtonType.Circle})

DataPanel Gauge

呈色

DataPanel({values:arr,type:DataPanelType.Line,max:200})
//Line,circle
Gauge({value:40,max:100,min:0})

Navigation 

Navigation(){
            
          Search({ placeholder:'搜索' })

          Text('内容')
           

        }
         
        .title(this.NavigationTitle())
        .toolBar(this.NavigationToolBar())

Stepper

Stepper(){
        StepperItem(){
          Column(){
            Text('1')
              
            
          }
          .width('100%')
          .height('100%')

        }
    //用于在右下显示按钮
        .nextLabel("下一步")

        StepperItem(){
          Column(){
            Text('2')
             
          }
        .nextLabel("下一步")
 //用于在左下显示按钮
        .prevLabel('上一步')

TextPicker和TextTimer

//range是数组
TextPicker({range:courses})

//controler控制他的开始暂停结束
textTimerController: TextTimerController = new TextTimerController()
TextTimer({controller:textTimerController})

Button('开始')
              .onClick(()=>{
                this.textTimerController.start()
              })
textTimerController.pause()
textTimerController.reset()

DatePicker和TimePicker

公农历切换

@State lunar:boolean = false
DatePicker()
          .lunar(this.lunar)

@State Military:boolean = false
TimePicker()
          .useMilitaryTime(this.Military)

PatternLock和QRcode 

  patternLockController: PatternLockController = new PatternLockController()
PatternLock(this.patternLockController)
          .sideLength(250)
          .onPatternComplete((input: Array<number>) => {
        //在里面写逻辑
}

QRCode('写要扫出来的内容')

Select

Select([{ //需要的对象},{value:'1',icon:$rawfile('paimon3.png')} ])

弹窗

ActionSheet

sheetInfo:Array<SheetInfo> = [{title:'HarmonyOS介绍',action:()=>{util.printf('HarmonyOS介绍')}}

ActionSheet.show({title:'请选择所要学习的内容',message:$r('app.string.CheckBoxName'),sheets:this.sheetInfo})

TextPickerDialog

private fruits: string[] = ['苹果', '橘子', '桃', '香蕉', '西瓜']
Button('文本滑动选择器弹窗')
        .onClick(()=>{
          TextPickerDialog.show({
                range:this.fruits,

          })

网络

  1. 在module.json5文件申请权限。
"requestPermissions": [  {    "name": "ohos.permission.INTERNET"  }],

     2. 绑定事件(HTTP请求不可复用)

    //创建httpRequest对象
    let httpRequest = http.createHttp();

    let url = "https://waylau.com/data/people.json";

    //发起HTTP请求
    let promise = httpRequest.request(
        //请求url地址
        url,
        {
        //请求方式
        method: http.RequestMethod.GET,
        //可选,默认为60s
        connectTimeout: 60000,
        //可选,默认为60s
        readTimeout: 60000,
//开发者根据自身业务需要添加header字段
        header: {
            'Content-Type': 'application/json'
        }
    });

    //处理响应结果
    promise.then((data) => {
        if (data.responseCode === http.ResponseCode.OK) {
            console.info('Result:' + data.result);
            console.info('code:' + data.responseCode);
            this.message = JSON.stringify(data.result);
        }
    }).catch((err) => {
        console.info('error:' + JSON.stringify(err));
    });
}

  • 13
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值