当前位置:网站首页>Wechat applet custom tabbar
Wechat applet custom tabbar
2022-06-24 20:34:00 【suoh's Blog】
effect :
Refer to the official website , Customize tabBar
Customize tabBar | Wechat open documents
1、 Configuration information
Need to be in app.json Set a property in custom, by true , On behalf of the global open custom tab


Be careful : When we set up custom After the attributes , that tabBar Below list Can the array be deleted ?
answer : Can not be , It has been clearly stated in the document that it cannot be deleted , You need to keep complete configuration items and customization is not applicable in the lower version tabBar, Therefore, compatibility is required 、

2、 Add code file .
The directory structure is fixed , You must create a folder in the project root directory : custom-tab-bar, And the corresponding documents .
In the first step custom Set to true, The applet can automatically read the index Components , Think of this component as tab renders .

Click on the plus sign , Create a new... In the root directory custom-tab-bar Folder
Then right-click the folder , Click New components, Input index, enter , Four files will be created automatically

At this point, we can see the bottom of the applet , It means that the creation is successful . Because he automatically recognized tabBar page .
3、 Write code in this directory .

After the establishment, we introduce vant In the component library tab Components :
First, in the js Under the document , introduce

"usingComponents": {
"van-tabbar": "/miniprogram_npm/@vant/weapp/tabbar/index",
"van-tabbar-item": "/miniprogram_npm/@vant/weapp/tabbar-item/index"
}And then again wxml writes vant Provided by the official website tabbar TAB bar

<van-tabbar active="{
{ active }}" bind:change="onChange">
<van-tabbar-item icon="wap-home"> home page </van-tabbar-item>
<van-tabbar-item icon="shopping-cart" info="5"> The shopping cart </van-tabbar-item>
<van-tabbar-item icon="manager" dot> my </van-tabbar-item>
</van-tabbar>stay js Write the variables provided on the official website under the file and click the switch button change event .

effect :

Be careful : Icons can be customized , See for yourself vant Just document , If you don't need it, just use it vant Icons provided , By modifying the icon Name to implement .

Be careful :
We want to modify it directly tabbar Style of component , You need to find the class name of the corresponding element , For example, I want to adjust the distance between the text and the icon :( tip : Hold down shift key Hold down the left mouse button , Pulling the simulator up and down can achieve the effect of zooming in and out .)

We can see , By default, he added a... To the icon margin value


Mainly the following code :
What does he mean ? intend margin-bottom Value get yes --tabbar-item-margin-bottom The value of this variable or 5px, If there are variables --tabbar-item-margin-bottom Just take the value of the variable , Otherwise the default 5px value .
margin-bottom: var(--tabbar-item-margin-bottom,5px);So let's modify this variable :
Define through the parent class stay index.wxss In the definition of :
.van-tabbar-item{
--tabbar-item-margin-bottom:0
}
After preservation , It didn't work :


After reading the document , It is found that this attribute needs to be enabled , Otherwise, modify in the custom component vant The default style of will not take effect
So we index.js Set in
options:{
styleIsolation:'shared'
},
You can see that the distance is not so big :

Let's simplify the code . Write this in a loop tabbar.
stay index.js Define a list
list:[
{
path:"pages/home/home",
icon:"wap-home",
text:" home page "
},
{
path:"pages/shopcart/shopcart",
icon:"shopping-cart",
text:" The shopping cart ",
info:10,
},
{
path:"pages/mine/mine",
icon:"manager",
text:" my "
}
]wxml writes : Because there is no guarantee that everyone needs a logo , therefore , We only define the shopping cart info attribute , Through three eye operation , To judge whether there is info, Show logo when it exists , Otherwise it doesn't show .
<van-tabbar active="{
{ active }}" bind:change="onChange">
<van-tabbar-item wx:for="{
{list}}" wx:key="index" info="{
{item.info?item.info:''}}" icon="{
{item.icon}}">{
{item.text}}</van-tabbar-item>
</van-tabbar>This is the end of the article , Next article , Talk about how to make the digital logo on the shopping cart , Dynamic plus change .
边栏推荐
- Bytebase rejoint la communauté de base de données open source d'alicloud polardb
- Map跟object 的区别
- Bytebase 加入阿里云 PolarDB 开源数据库社区
- 图像PANR
- With its own cells as raw materials, the first 3D printing ear transplantation was successful! More complex organs can be printed in the future
- Dongyuhui is not enough to bring goods to "rescue" live broadcast
- 科技抗疫: 运营商网络洞察和实践白皮书 | 云享书库NO.20推荐
- [video tutorial] functions that need to be turned off in win10 system. How to turn off the privacy option in win10 computer
- Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
- RF_ DC system clock setting gen1/gen2
猜你喜欢

Bytebase 加入阿里云 PolarDB 开源数据库社区

顺序栈1.0版本

Set up your own website (14)

Dongyuhui is not enough to bring goods to "rescue" live broadcast

Q1: error in JMeter filename must not be null or empty

Internet of things? Come and see Arduino on the cloud

Basic operation of sequence table

Teach you how to cancel computer hibernation

Behind Tiantian Jianbao storm: tens of millions in arrears, APP shutdown, and the founder's premeditated plan to run away?

微信小程序中使用vant组件
随机推荐
Simulation lottery and probability statistics experiment of the top 16 Champions League
物联网?快来看 Arduino 上云啦
等保备案是等保测评吗?两者是什么关系?
C語言實現掃雷(簡易版)
First understand redis' data structure - string
开放可编程基础设施(OPI)项目,重新定义DPU/IPU
Vxlan and MPLS: from data center to Metro Ethernet
The Network Security Review Office launched a network security review on HowNet, saying that it "has a large amount of important data and sensitive information"
科技抗疫: 运营商网络洞察和实践白皮书 | 云享书库NO.20推荐
VMware virtual machine setting static IP
[普通物理] 光栅衍射
Compressed list of redis data structures
Stackoverflow annual report 2022: what are developers' favorite databases?
C language to realize mine sweeping (simple version)
天天鉴宝暴雷背后:拖欠数千万、APP停摆,创始人预谋跑路?
微信小程序中使用vant组件
实现基于Socket自定义的redis简单客户端
云计算发展的 4 个阶段,终于有人讲明白了
[cann document express issue 04] unveiling the development of shengteng cann operator
What is showcase? What should showcase pay attention to?
https://vant-contrib.gitee.io/vant-weapp/#/tabbar