鸿蒙5.0开发进阶:JS组件-tabs

往期鸿蒙5.0全套实战文章必看:(文中附带全栈鸿蒙5.0学习资料)


tabs

说明

从API version 4开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

tab页签容器。

权限列表

子组件

仅支持<tab-bar>和<tab-content>。

属性

除支持通用属性外,还支持如下属性:

名称类型默认值必填描述
indexnumber0当前处于激活态的tab索引。
verticalbooleanfalse

是否为纵向的tab,默认为false,可选值为:

- false:tabbar和tabcontent上下排列。

- true:tabbar和tabcontent左右排列。

样式

支持通用样式

事件

除支持通用事件外,还支持如下事件:

名称参数描述
change{ index: indexValue }tab页签切换后触发,动态修改index值不会触发该回调。

示例

<!-- xxx.hml -->
<div class="container">
  <tabs class = "tabs" index="0" vertical="false" onchange="change">
    <tab-bar class="tab-bar" mode="fixed">
      <text class="tab-text">Home</text>
      <text class="tab-text">Index</text>
      <text class="tab-text">Detail</text>
    </tab-bar>
    <tab-content class="tabcontent" scrollable="true">
      <div class="item-content" >
        <text class="item-title">First screen</text>
      </div>
      <div class="item-content" >
        <text class="item-title">Second screen</text>
      </div>
      <div class="item-content" >
        <text class="item-title">Third screen</text>
      </div>
    </tab-content>
  </tabs>
</div>
/* xxx.css */
.container {
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
}
.tabs {
  width: 100%;
}
.tabcontent {
  width: 100%;
  height: 80%;
  justify-content: center;
}
.item-content {
  height: 100%;
  justify-content: center;
}
.item-title {
  font-size: 60px;
}
.tab-bar {
  margin: 10px;
  height: 60px;
  border-color: #007dff;
  border-width: 1px;
}
.tab-text {
  width: 300px;
  text-align: center;
}
// xxx.js
export default {
  change: function(e) {
    console.log("Tab index: " + e.index);
  },
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值