当前位置:网站首页>Wechat applet custom tabbar (session customer service) vant
Wechat applet custom tabbar (session customer service) vant
2022-06-13 06:13:00 【Vue sauce】
The effect to be achieved :
In the process of writing the project , May meet ui Design conversation customer service on tabbar On the situation , But the session message must go through button Trigger , However, the default of goose applet tabbar Highest level , There is no way to add button event , At this time , We need to implement a custom tabbar, I use it Vant ui Component library , Others will do , The main principle is tabbar Put a button on it , Block the original tab Just do it !
Vant Applet website ( It must be a small program version , Before the introduction of vue Version of , It can't be realized , After troubleshooting for a long time )
Applet customization tabbar Official website tutorial
First step :
//app.json json The file cannot write comments , But to prompt important steps , I wrote ha ha
"tabBar": {
"custom": true, // Turn on custom tabbar
"color": "#1B1B1B",
"selectedColor": "#00c56b",
"borderStyle": "black",
"backgroundColor": "#fafbfe",
"list": [
//tabbar The path of , Although it is customized , You still have to write all the paths ,
/* * a key : You may find that the customer service tabbar Be missing , This is because our customer service also needs to bind a page ( Custom jump needs to be bound with jump path ), If it is written here, it will appear that you clicked customer service , When you return, the bound blank page will be displayed , This is definitely not what we want , So it doesn't say , Will return to the previous page path , There will be no blank pages */
{
"pagePath": "pages/groupChat/groupChat",
"text": " Group chat "
},
{
"pagePath": "pages/newMessage/newMessage",
"text": " information "
},
{
"pagePath": "pages/newChat/newChat",
"text": " Chat "
},
{
"pagePath": "pages/mine/mine",
"text": " my "
}
]
},
"usingComponents": {
// These two were introduced by us vant tabbar Components , Also on the page json quote , Look at your own code habits , The global availability introduced here
"van-tabbar": "@vant/weapp/tabbar/index",
"van-tabbar-item": "@vant/weapp/tabbar-item/index",
}
The second step : Add... To the code root directory tabBar Code entry file :
The third step :
//custorm-tab-bar/index.wxml page
<van-tabbar active="{
{ active }}" bind:change="onChange" active-color="#07c160" inactive-color="#1b1b1b">
<van-tabbar-item >
<image slot="icon" src="/images/tabbar/groups.png" mode="aspectFit" />
<image slot="icon-active" src="/images/tabbar/groups_on.png" mode="aspectFit" />
Group chat
</van-tabbar-item>
<van-tabbar-item>
<image slot="icon" src="/images/tabbar/server.png" mode="aspectFit" />
<image slot="icon-active" src="/images/tabbar/serverActive.png" mode="aspectFit" />
<!-- Call up the conversation customer service button-->
<button class="serverButton" hover-class="btn-hover" openType="contact"> </button>
<text class="hintText"> Customer service </text>
</van-tabbar-item>
<van-tabbar-item >
<!-- The displayed... Is not selected icon-->
<image slot="icon" src="/images/tabbar/msg.png" mode="aspectFit" />
<!-- Check the displayed icon-->
<image slot="icon-active" src="/images/tabbar/msgActive.png" mode="aspectFit" />
information
</van-tabbar-item>
<van-tabbar-item >
<image slot="icon" src="/images/tabbar/groupChat.png" mode="aspectFit" />
<image slot="icon-active" src="/images/tabbar/groupChatActive.png" mode="aspectFit" />
Chat
</van-tabbar-item>
<van-tabbar-item >
<image slot="icon" src="/images/tabbar/my.png" mode="aspectFit" />
<image slot="icon-active" src="/images/tabbar/myActive.png" mode="aspectFit" />
my
</van-tabbar-item>
</van-tabbar>
//custorm-tab-bar/index.js page
Component({
data: {
active:0, // By default tab
list: [
/*tabbar route , Actually van-tabbar-item The cyclic data of can be written here , For example, the picture before clicking , And the image path after clicking , And then in wxml page wx:for Circulation is enough */
{
pagePath: "/pages/groupChat/groupChat", },
{
pagePath: "/pages/serverPage/serverPage", },
{
pagePath: "/pages/newMessage/newMessage",},
{
pagePath: "/pages/newChat/newChat", },
{
pagePath: "/pages/mine/mine", }
]
},
methods: {
// Click on tab
onChange(e) {
// console.log(e,'e',this.data.active)
this.setData({
active: e.detail }); // Switch tab
// console.log(this.data.active,"active",e.detail)
wx.switchTab({
// Switch pages
url: this.data.list[e.detail].pagePath
});
},
init() {
const page = getCurrentPages().pop();
this.setData({
active: this.data.list.findIndex(item => item.pagePath === `/${
page.route}`)
});
}
}
})
//custorm-tab-bar/index.wxss page
image{
width: 30px;
height: 18px;
}
button::after {
border: none; // Remove the default button Border
}
button {
background: #ffffff;
font-size: 24rpx;
line-height: 24rpx;
}
.button-hover{
background: #ffffff; // Remove the default button Background color of
}
.serverButton {
// a key : Our customer service btn It is fixed and positioned on tabbar Upper , We need to block it completely tab Click event , It needs to be positioned according to its position
// The key css Note yes * Number
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: fixed; // * Fixed position
width: 20%; //* Look at you tab There are several , Calculation : 100% / tab Number
bottom: 0; // *
height: 100rpx; //*tab Height
opacity: 0; //* If the button is transparent, it will not be blocked icon
left: 20%; // * Offset , Calculation : width * index
}
.activeButton{
color: #07c160; /* Because the default tab Blocked click events , We need to change the text color when we focus } .serverText { font-size: 12px; line-height: 12px; }
summary : Important steps are annotated , As long as you import components correctly , The code should be copied and available , The image path needs to be changed to your local image path , Do not understand the parameters in the component , Official documents also introduce
边栏推荐
- Uni app dynamic setting title
- 【美团笔试题】
- [MySQL] basic knowledge review
- High burst solution 2
- 微信小程序:点击事件获取当前设备信息(基础)
- Experience of redis installation under Linux system (an error is reported at the same time. The struct redis server does not have a member named XXXX)
- 【var const let区别】
- Fichier local second Search Tool everything
- [DP 01 backpack]
- Uniapp dynamically shows / hides the navigation bar return button
猜你喜欢
杨辉三角形详解
Annotation only integration SSM framework
1+1 > 2, share creators can help you achieve
1+1>2,Share Creators可以帮助您实现
Test logiciel - résumé des FAQ d'interface
Echart histogram: echart implements stacked histogram
[spark]spark introductory practical series_ 8_ Spark_ Mllib (upper)__ Introduction to machine learning and sparkmllib
You still can't remotely debug idea? Come and have a look at my article. It's easy to use
The SQL file of mysql8.0 was imported into version 5.5. There was a pit
HBuilderX:HBuilderX安装以及其常用插件安装
随机推荐
Echart柱状图:x轴显示value,y轴显示类别
Leetcode- detect uppercase letters - simple
Annotation only integration SSM framework
Leetcode- key formatting - simple
华为开发者认证与DevEco Studio编译器下载
Self summarizing
Echart折线图:多条折线图每次仅展示一条
Leetcode fizz buzz simple
Echart histogram: X-axis displays value, Y-axis displays category
推荐扩容工具,彻底解决C盘及其它磁盘空间不够的难题
[written examination questions of meituan]
Leetcode longest harmonic subsequence simple
自我总结ing
Leetcode Timo attack - simple
1+1 > 2, share creators can help you achieve
[spark]spark introductory practical series_ 8_ Spark_ Mllib (lower)__ Machine learning library sparkmllib practice
Applet disable native top
Experience of redis installation under Linux system (an error is reported at the same time. The struct redis server does not have a member named XXXX)
php redis 制作高迸发秒杀
@The detailed explanation of configurationproperties and the problem that all properties of the entity bean modified by this annotation are null after injection are solved