当前位置:网站首页>HarmonyOS应用开发第二次作业笔记
HarmonyOS应用开发第二次作业笔记
2022-06-21 23:13:00 【某科学的初学者】
1.自定义组件
JS UI框架支持自定义组件,用户可根据业务需求将已有的组件进行扩展,增加自定义的私有属性和事件,封装成新的组件,方便在工程中多次调用,提高页面布局代码的可读性。
- 定义一个专门存放自定义组件的文件夹 components.tabbar 并设置3个基础文件 tabbar.hml、tabbar.js、tabbar.css,需要注意的是:3个文件的文件名必须保持一致,不然会存在找不到文件的情况。该自定义组件的目的是给页面底部配置一个 tabbar 选项卡体验。
- 设置底部选项卡对应的 json 数据源,用来保存 icon 图片、标题,以及点击选中后的 icon 图片。
自定义组件是用户根据业务需求,将已有的组件组合,封装成的新组件,可以在工程中多次调用,提高代码的可读性。
自定义组件通过element引入到宿主页面,使用方法:
<element name='comp' src='../../components/tabbar/tabbar.hml'></element>
<div class="container">
<text class="title">
首页
</text>
<comp></comp>
</div>name 属性指自定义组件名称(非必填),组件名称对大小写不敏感,默认使用小写,src 属性指自定义组件hml 文件路径(必填),若没有设置 name 属性,则默认使用 hml 文件名作为组件名。
事件绑定:自定义组件中绑定子组件事件使用 (on|@)child1 语法,子组件中通过 this.$emit('child1', { params: '传递参数' }) 触发事件并进行传值,父组件执行 bindParentVmMethod 方法并接收子组件传递的参数。
2.父子组件通信
Props 自定义组件可以通过 props 声明属性,父组件通过设置属性向子组件传递参数,camelCase(驼峰命名法)的 prop 名,在外部父组件传递参数时需要使用 kebab-case (短横线分隔命名)形式,即当属性compProp 在父组件引用时需要转换为 comp-prop。
添加默认值,子组件可以通过固定值 default 设置默认值,当父组件没有设置该属性时,将使用其默认值。此情况下 props 属性必须为对象形式,不能用数组形式。
数据单向性,父子组件之间数据的传递是单向的,只能从父组件传递给子组件,子组件不能直接修改父组件传递下来的值,可以将 props 传入的值用 data 接收后作为默认值,再对 data 的值进行修改。
边栏推荐
- Infant name [adjacency matrix and DFS of connected components]
- Hotline salon issue 26 - cloud security session
- 滴滴工程效能平台建设之路
- Mathematical knowledge: sum of divisors - divisors
- [wechat applet] 40029 invalid code solution set
- [安洵杯 2019]吹着贝斯扫二维码
- root检测实现
- buuctf misc 间谍启示录
- AttributeError: ‘WebDriver‘ object has no attribute ‘w3c‘
- 【愚公系列】2022年06月 通用职责分配原则(九)-受保护变量原则
猜你喜欢
随机推荐
If a programmer goes to prison, will he be assigned to write code?
数学知识:约数之和—约数
以父之名活动攻略(可以薅羊毛啦)
Go Web 编程入门:验证器
【剑指Offer】43. 1~n 整数中 1 出现的次数
buuctf pwn ciscn_2019_n_8
rabbit:do_run_postlaunch_phase/0 line 932
客户端建设及调优实践
Get the value value according to the key in the data
Recruitment brochure for traditional product manager international qualification certification (NPDP) in the second half of 2022
Cloud whale took the lead in arranging door-to-door services to see how it broke through the industry "blockade" with services
[Yugong series] general responsibility allocation principle in June 2022 (IX) - principle of protected variables
All kinds of FPN in object detection
[wechat applet] some pitfalls and precautions of wechat applet using the form
Lectures explanation for unsupervised graph level representation learning (usib)
Leetcode 279. Carré parfait carré complet (moyen)
Introduction to activities in the name of the father (you can collect sheep)
一些代码静态检查工具的简介
滴滴工程效能平台建设之路
【微信小程序】微信小程序使用表单的一些坑和注意事项

![[RoarCTF2019]黄金6年](/img/c4/07caf5dc8f27f77b724753b5f87a0a.png)







