当前位置:网站首页>The second harmonyos application development training
The second harmonyos application development training
2022-06-22 21:25:00 【Rookie no】
Implementation of parent-child component communication function
<element name="ctest" src="../../components/ctest/ctest.hml"></element>
<div class="container">
<ctest name=" Parent to child content "></ctest>
</div><!-- It is important to note that : Subcomponents hml、js、css The three file names must be consistent -->
<div class="ctest">
<text class="title"> I am a subcomponent </text>
<text>{
{ name }}</text>
</div>export default {
// props:[ "name" ],
props:{
name:{
default: ' Default content '
}
}
}Props Custom components can be created by props Declarative attribute , The parent component passes parameters to the child component by setting properties ,camelCase( Hump nomenclature ) Of prop name , When an external parent component passes parameters, it needs to use kebab-case ( Short horizontal lines separate the names ) form , That is, when attribute compProp When the parent component references, it needs to be converted to comp-prop.
Add default , Subcomponents can be defined by fixed values default Set the default value , When the parent component does not set this property , Its default value will be used . In this case props Property must be in object form , It can't be in an array .
Data unidirectionality , The data transfer between parent and child components is one-way , Can only be passed from parent component to child component , The child component cannot directly modify the value passed down by the parent component , Can be props The value passed in is in data As the default value after receiving , Right again data Change the value of .
- The definition of subcomponents
- Call of parent component
Routing function implementation
1. Page definition
stay Pages Create a new folder under the folder to represent the required route , Of course , We can also create a new one Ablity Experience , Here's a demonstration Pages.Name.
stay Under the new folder, be sure to create three new files
index.hml、index.js、index.cssThree files , The file name must use index To name it , Using other names will result in file dependencies not being found .Shortcut , You can select the corresponding Ability Pages Under the folder , then new page Add page directly , And will automatically register the route , This is more convenient
stay config.json In file

2. Use of routes
- Import routing module
import router from '@system.router';- router.push(OBJECT), Jump to the specified page in the application .
- router.replace(OBJECT), Replace the current page with a page in the application , And destroy the replaced page .
- router.back(OBJECT), Return to the previous page or the specified page .
// index page ,uri The field is page routing , By... In the configuration file pages List assignments .
router.push({
uri: 'pages/detail/detail',
});
// detail page
router.push({
uri: 'pages/mall/mall',
});
// mall Page passing back, Will return detail page
router.back();
// detail Page passing back, Will return index page
router.back();
// adopt back, Back to detail page
router.back({uri:'pages/detail/detail'});- router.clear(), Clear all history pages in the page stack , Only keep the current page as the top page of the stack .
- router.getLength(), Get the number of pages currently in the page stack .
- router.getState(), Get the status information of the current page .
PS: Page routing can only be called after page rendering , stay onInit and onReady In the life cycle, the page is still in the rendering stage , It is forbidden to call page routing method .
边栏推荐
- 88- widely circulated parameter optimization, honey or poison?
- 程序员必看的学习网站
- 72 results and development suggestions of the latest on-site production system optimization
- NBA playoff match chart
- 数据库总结:mysql在开发过程中常见的问题及优化
- [the penultimate node in the linked list]
- PHP image making
- 查询es分页下标超过1万
- Pytorch's model saving, loading and continuing training
- 79- do not create desc descending index when you see order by XXX desc - there is book donation benefit at the end of the article
猜你喜欢

RealNetworks vs. 微软:早期流媒体行业之争
![[21. merge two ordered linked lists]](/img/ce/45b8cc740c8632f0cedc3ffd31620a.png)
[21. merge two ordered linked lists]
![[876. intermediate node of linked list]](/img/c8/463d150bc6c88cfb57e94795957b0e.png)
[876. intermediate node of linked list]
![[513. find the value in the lower left corner of the tree]](/img/6d/b2ec8e3072a65c20c586941e6b2a85.png)
[513. find the value in the lower left corner of the tree]

Moke 6. Load balancing ribbon

2022年山东省安全员C证考试试题模拟考试平台操作

【CM11 链表分割】
![[redis]配置文件](/img/1c/05c06d59c9efb5983f877822db333c.png)
[redis]配置文件

Laravel+ pagoda planning task
![[redis]redis6 master-slave replication](/img/47/3be33a0d7435bd75cdd6e7b4ea51d4.png)
[redis]redis6 master-slave replication
随机推荐
Operation of simulation test platform for 2022 Shandong safety officer C certificate test
php 镜像制作
win10安装.net3.5.docx
ACM. HJ45 名字的漂亮度 ●●
es 按条件查询数据总条数
[redis]Redis6的主从复制
万字长文 | 使用 RBAC 限制对 Kubernetes 资源的访问
ACM. HJ24 合唱队 ●●
HarmonyOS应用开发培训第二次
84- I am on Internet & lt; 52 SQL statement performance optimization strategies & gt; Some views of
300. 最长递增子序列 ●●
Arcgis中las点云数据抽稀
[138. copy linked list with random pointer]
【20. 有效的括号】
苹果CoreFoundation源代码
[redis]redis6 master-slave replication
杰理之动态切换 EQ 文件【篇】
NumPy学习笔记(六)——sum()函数
云服务器中安装mysql(2022版)
Code to image converter