标签:index 自定义 微信 --- item static tabbar text png
0. 文档位置
自定义tabbarhttps://developers.weixin.qq.com/miniprogram/dev/framework/ability/custom-tabbar.html
1. 使用
1.1 随便创建一个文件夹---创建一个commponent
1.2 html
<!--miniprogram/custom-tab-bar/index.wxml-->
<cover-view class="tab-bar">
<cover-view class="tab-bar-border"></cover-view>
<cover-view wx:for="{{list}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="switchTab">
<block wx:if="{{ index === 1 }}" >
<cover-view class="pub">{{item.text}}</cover-view>
</block>
<block wx:else>
<cover-image src="{{selected === index ? item.selectedIconPath : item.iconPath}}"></cover-image>
<cover-view style="color: {{selected === index ? selectedColor : color}}">{{item.text}}</cover-view>
</block>
</cover-view>
</cover-view>
1.3 css
.tab-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 48px;
background: white;
display: flex;
padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar-border {
background-color: rgba(0, 0, 0, 0.33);
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 1px;
transform: scaleY(0.5);
}
.tab-bar-item {
flex: 1;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.tab-bar-item cover-image {
width: 27px;
height: 27px;
}
.tab-bar-item cover-view {
font-size: 10px;
}
.pub {
background-color: #fa3d;
height: 80rpx;
width: 80rpx;
border-radius: 50%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
1.4 js
var app = getApp();
Component({
properties: {
selected: {
type: Number, // html选中找两个地方,一个data,一个属性
value: 0
}
},
data: {
color: "#7A7E83", // 颜色
selectedColor: "#FF0000", // 被选中颜色
list: [{
pagePath: "/pages/index/index",
iconPath: "/static/tabbar/no.png",
selectedIconPath: "/static//tabbar/yes.png",
text: "首页"
},
{
text: "发布"
},
{
pagePath: "/pages/home/home",
iconPath: "/static/tabbar/no.png",
selectedIconPath: "/static/tabbar/yes.png",
text: "我的"
}
]
},
attached() {},
methods: {
switchTab(e) {
var data = e.currentTarget.dataset // const常量
var url = data.path
// 跳转非tababr
// wx.navigateTo({
// url: url,
// })
// 跳转tababr
// 如果·有path
if (url) {
wx.switchTab({
url
})
} else {
if (app.globalData.userinfo) {
wx.navigateTo({
url: '/pages/upload/upload',
})
} else {
wx.navigateTo({
url: '/pages/login/login',
})
}
}
// this.setData({
// selected: data.index
// })
}
}
})
1.5 全局app.json配置
"tabBar": {
"selectedColor": "#FF0000",
"custom": true,
"list": [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "/static/tabbar/no.png",
"selectedIconPath": "/static//tabbar/yes.png"
},
{
"pagePath": "pages/home/home",
"text": "我的",
"iconPath": "/static/tabbar/no.png",
"selectedIconPath": "/static/tabbar/yes.png"
}
]
},
1.6 使用的界面配置(在哪个界面使用了,就在哪个界面配置)
1.6.1 app.json
{
"usingComponents": {
"tabber": "/commponents/tabbar"
}
}
1.6.2 html(写在最后/最前) 这个页面是我的 索引为2
<!--选中的索引,根据tabbar中js配的菜单位置,自己调整-->
<tabber selected="{{ 2 }}"></tabber>
标签:index,自定义,微信,---,item,static,tabbar,text,png 来源: https://blog.csdn.net/qq_52385631/article/details/123173593
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。