微信小程序|搭建一个博客小程序

69 篇文章 918 订阅 ¥9.90 ¥99.00
  • 46
    点赞
  • 90
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 73
    评论
要在微信小程序搭建一个底部导航栏,可以按照以下步骤进行: 1. 在 app.json 文件中配置底部导航栏的样式和页面路径 在 app.json 文件中,可以通过 tabBar 字段来配置底部导航栏的样式和页面路径。例如: ``` "tabBar": { "color": "#999", "selectedColor": "#07c160", "backgroundColor": "#fff", "borderStyle": "black", "list": [ { "pagePath": "pages/index/index", "text": "首页", "iconPath": "images/tab-bar/home.png", "selectedIconPath": "images/tab-bar/home-active.png" }, { "pagePath": "pages/cart/cart", "text": "购物车", "iconPath": "images/tab-bar/cart.png", "selectedIconPath": "images/tab-bar/cart-active.png" }, { "pagePath": "pages/user/user", "text": "我的", "iconPath": "images/tab-bar/user.png", "selectedIconPath": "images/tab-bar/user-active.png" } ] } ``` 其中,color 和 selectedColor 分别表示未选中和选中时的文字颜色,backgroundColor 表示背景色,borderStyle 表示边框样式,list 中的每一个对象表示一个底部导航栏的选项,pagePath 表示对应的页面路径,text 表示文字描述,iconPath 和 selectedIconPath 分别表示未选中和选中时的图标路径。 2. 在 app.wxss 文件中设置底部导航栏的样式 在 app.wxss 文件中,可以设置底部导航栏的样式。例如: ``` .tab-bar { position: fixed; bottom: 0; left: 0; width: 100%; display: flex; justify-content: space-around; align-items: center; background-color: #fff; border-top: 1px solid #ccc; } .tab-bar-item { display: flex; flex-direction: column; justify-content: center; align-items: center; } .tab-bar-item-text { font-size: 12px; margin-top: 6px; } .tab-bar-item-icon { width: 24px; height: 24px; } ``` 其中,.tab-bar 表示底部导航栏的样式,.tab-bar-item 表示每一个选项的样式,.tab-bar-item-text 和 .tab-bar-item-icon 分别表示文字和图标的样式。 3. 在各个页面中设置底部导航栏的选中状态 在各个页面中,可以通过设置页面的 onShow 函数和页面路径来设置底部导航栏的选中状态。例如: ``` onShow: function() { wx.setNavigationBarTitle({ title: '首页' }) const currentPage = getCurrentPages().pop() if (currentPage.route === 'pages/index/index') { this.setData({ activeTabBarIndex: 0 }) } } ``` 其中,wx.setNavigationBarTitle 可以设置页面的标题,getCurrentPages().pop() 可以获取当前页面的路径,this.setData 可以设置页面的数据,activeTabBarIndex 表示当前选中的底部导航栏的索引。通过判断当前页面的路径来设置相应的选中状态。 通过以上步骤,就可以在微信小程序搭建一个底部导航栏了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 73
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

摔跤猫子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值