当前位置:网站首页>How to implement tabbar title bar with list component
How to implement tabbar title bar with list component
2022-07-02 11:00:00 【Huawei Developer Forum】
Requirements describe
When we don't want to use tabbar When the component implements the title bar , Are there any other options ?
Demand analysis
The answer is list Components , adopt list Component setting style flex-direction: row; It can meet the effect of horizontal display title , meanwhile , Adding style switching when clicking on the title can meet the effect of dynamic display .
Suppose you define an array , Used to indicate the content of the title , The elements of the array need to contain both the name of the title and the color of the click , When we click on the corresponding title , You can set the color of the clicked title to red , Other UN clicked titles are set to black .
The effect is as follows ( Click on “ economic ” and “ music ” title ):


The key codes are as follows :
<list class="list" for="{
{listData}}">
<list-item class="list-item" type="item">
<text class="text_{
{$item.color}}" onclick="changeColor($idx,$item.color)">{
{ $item.name }}</text>
</list-item>
</list>
listData: [
{ color: "black", name: " sports " },
{ color: "black", name: " Politics " },
{ color: "black", name: " social " },
{ color: "black", name: " economic " },
{ color: "black", name: " literature " },
{ color: "black", name: " music " },
{ color: "black", name: " The fine arts " },
{ color: "black", name: " current affairs " },
]
changeColor: function ($idx, color, evt) {
if (this.num === $idx) {
this.listData[$idx].color = "red"
}
else {
this.listData[$idx].color = "red"
this.listData[this.num].color = "black"
this.num = $idx
}
console.log("changeColor" + $idx);
}
Solution
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<div>
<list class="list" for="{
{listData}}">
<list-item class="list-item" type="item">
<text class="text_{
{$item.color}}" onclick="changeColor($idx,$item.color)">{
{ $item.name }}</text>
</list-item>
</list>
</div>
</div>
</template>
<style>
.list {
flex-direction: row;
height: 50px;
}
.list-item {
width: 80px;
margin-left: 10px;
}
.container {
flex-direction: column;
}
.text {
font-size: 30px;
}
.text_red {
color: #dc143c;
}
.text_black {
color: rgba(0, 0, 0, 0.54);
}
</style>
<script>
module.exports = {
data: {
num: 0,
color: '',
listData: [
{ color: "black", name: " sports " },
{ color: "black", name: " Politics " },
{ color: "black", name: " social " },
{ color: "black", name: " economic " },
{ color: "black", name: " literature " },
{ color: "black", name: " music " },
{ color: "black", name: " The fine arts " },
{ color: "black", name: " current affairs " },
]
},
onInit() {
},
changeColor: function ($idx, color, evt) {
if (this.num === $idx) {
this.listData[$idx].color = "red"
}
else {
this.listData[$idx].color = "red"
this.listData[this.num].color = "black"
this.num = $idx
}
console.log("changeColor" + $idx);
}
}
</script>
For more details , Please see the :
Introduction to Bluetooth interface :
边栏推荐
- PCL 从一个点云中提取一个子集
- 【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
- JSP webshell免殺——JSP的基礎
- 洛谷 P5536 【XR-3】核心城市(贪心 + 树形 dp 寻找树的中心)
- Hdu1236 ranking (structure Sorting)
- [visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)
- UVM factory mechanism
- 华为AppLinking中统一链接的创建和使用
- Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)
- MySQL environment configuration
猜你喜欢

二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)

Kustomize使用手册

axis设备的rtsp setup头中的url不能带参

2022爱分析· 国央企数字化厂商全景报告

从MediaRecord录像中读取H264参数
![[SUCTF2018]followme](/img/63/9104f9c8bd24937b0fc65053efec96.png)
[SUCTF2018]followme

618 what is the secret of dominating the list again? Nike's latest financial report gives the answer

Operator-1 first acquaintance with operator

Win11 arm系统配置.net core环境变量

HDU1228 A + B(map映射)
随机推荐
Start class, data analysis, high salary training plan, elite class
转换YV12到RGB565图像转换,附YUV转RGB测试
UVM learning - build a simple UVM verification platform
nodejs+express+mysql简单博客搭建
Easyexcel, a concise, fast and memory saving excel processing tool
Primary key policy problem
PCL eigen introduction and simple use
php中self和static在方法中的区别
js promise. all
Oracle 笔记
Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)
Special topic of binary tree -- acwing 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)
Win11 arm系统配置.net core环境变量
MySQL数据库远程访问权限设置
PCL Eigen介绍及简单使用
Logu p3398 hamster looks for sugar (double LCA on the tree to judge whether the two paths in the tree intersect)
Learn open62541 -- [66] UA_ Generation method of string
1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
1287_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
UVM learning - object attribute of UVM phase