当前位置:网站首页>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 :
边栏推荐
- P1055 [noip2008 popularization group] ISBN number
- Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
- Read H264 parameters from mediarecord recording
- JS settimeout() and interview questions
- PCL之K-d树与八叉树
- HDU1236 排名(结构体排序)
- 洛谷 P3398 仓鼠找 sugar(树上倍增 lca 判断树中两条路径是否相交 结论)
- Pywin32 opens the specified window
- Record attributeerror: 'nonetype' object has no attribute 'nextcall‘
- 主键策略问题
猜你喜欢
JSP webshell免杀——webshell免杀
Common methods of JS array
LabVIEW为什么浮点数会丢失精度
【深入浅出玩转FPGA学习3-----基本语法】
(五)APA场景搭建之挡位控制设置
MySQL environment configuration
Special topic of binary tree -- Logu p1229 traversal problem (the number of traversals in the middle order is calculated when the pre and post order traversals of the multiplication principle are know
12. Process synchronization and semaphore
Dialogue Wu Gang: why do I believe in the rise of "big country brands"?
Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
随机推荐
AppGallery Connect场景化开发实战—图片存储分享
Record attributeerror: 'nonetype' object has no attribute 'nextcall‘
Learn open62541 -- [66] UA_ Generation method of string
华为联机对战服务玩家掉线重连案例总结
Hdu1236 ranking (structure Sorting)
Binary tree topic -- p1030 [noip2001 popularization group] find the first order
Oracle 笔记
QT学习日记8——资源文件添加
Analysis of hot spots in AI technology industry
Logu p3398 hamster looks for sugar (double LCA on the tree to judge whether the two paths in the tree intersect)
Matlab processing of distance measurement of experimental electron microscope
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
UWA report uses tips. Did you get it? (the fourth bullet)
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
php中self和static在方法中的区别
Luogu p4281 [ahoi2008] emergency gathering / gathering (tree doubling LCA)
Special topic of binary tree -- acwing 19 The next node of the binary tree (find the successor of the node in the tree)
拆解美图SaaS:开着飞机换引擎
主键策略问题