微信小程序自定义底部导航栏组件
作者:weixin_43865030 发布时间:2024-07-28 21:06:08
标签:微信小程序,导航栏
本文实例为大家分享了微信小程序底部导航栏组件的具体实现代码,供大家参考,具体内容如下
1、在自己项目的公共组件的文件价下新建tabbar.vue(定义的自定义导航栏组件)
<template>
<view v-if="showTabbar" class="tabbar">
<view
v-for="(item, index) in tabList"
:key="index"
class="icon"
@click="switchTabBar(item.path, index)"
>
<image :src="index == current ? item.iconActivePath : item.iconPath"></image>
<text :class="index == current ? 'active_text' : 'text'" bindtap = 'go'>{{ item.name }}</text>
</view>
</view>
</template>
<script>
// import container from '@/channelMessage/get-container'
export default {
props: {
showTabbar: {
type: Boolean,
default: true,
},
current:{ // 当前页面index
type:Number,
default:0
},
},
data() {
return {
selectedIndex: 0,
tabList: [
{
name: "首页",
iconPath: require("../../../static/image/img/tab-home-nor.png"),
iconActivePath: require("../../../static/image/img/tab-home-sel.png"),
path: "/pages/index/index",
},
{
name: "购物车",
iconPath: require("../../../static/image/img/tab-cart-nor.png"),
iconActivePath: require("../../../static/image/img/tab-cart-sel.png"),
path: "/pages/cart/cartEdit",
},
{
name: "我的",
iconPath: require("../../../static/image/img/tab-my-nor.png"),
iconActivePath: require("../../../static/image/img/tab-my-sel.png"),
path: "/pages/mine/mine",
},
],
}
},
onShow() {
// const containerId = container.getContainerId()
// if (containerId == '1000') {
// this.showTabbar = false
// }
},
methods: {
switchTabBar(path, index) {
this.item_index = index
wx.switchTab({
url: path,
})
// this.$router.replace(path)
},
},
}
</script>
<style lang="scss" scoped>
.tabbar {
position: fixed;
bottom: 0;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-around;
width: 100%;
height: 100rpx;
background-color: #ffffff;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
.icon {
display: flex;
flex-direction: column;
align-items: center;
image {
width: 50rpx;
height: 50rpx;
}
}
.active_text{
font-size: 20rpx;
margin-top: 5rpx;
color: #d81e06;
}
.text{
font-size: 20rpx;
margin-top: 5rpx;
}
}
</style>
2、在项目中的pages.json文件中新增代码,保证tabbar.vue中的wx.switchTab可以正常使用,代码如下:
"tabBar": {
"selectedColor": "#EE2F51",
"list": [{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "static/image/img/tab-home-nor.png",
"selectedIconPath": "static/image/img/tab-home-sel.png"
},{
"pagePath": "pages/cart/cartEdit",
"text": "购物车",
"iconPath": "static/image/img/tab-cart-nor.png",
"selectedIconPath": "static/image/img/tab-cart-sel.png"
},{
"pagePath": "pages/mine/mine",
"text": "我的",
"iconPath": "static/image/img/tab-my-nor.png",
"selectedIconPath": "static/image/img/tab-my-sel.png"
}]
},
3、在main.js中全局注册自定义组件
import tabBar from "./customComponents/commonComponents/tabBar/index.vue";
//换自己的组件位置,这里的index.vue就是前面所说的tabbar.vue
Vue.component("tabBar", tabBar);
4、在需要使用导航栏的页面引入注册的组件
//为页面引入导航栏组件
<tabBar :current=item_index></tabBar>
//标记状态,是的导航栏可以根据页面显示不同的激活状态
data() {
return {
item_index: 0,
}
}
//隐藏微信自带的导航栏
onLoad() {
wx.hideTabBar();
},
5、展示效果
来源:https://blog.csdn.net/weixin_43865030/article/details/120852452


猜你喜欢
- 前言:线程是指进程内的一个执行单元,也是进程内的可调度实体.与进程的区别:(1) 地址空间:进程内的一个执行单元;进程至少有一个线程;它们共
- 什么是pdb不知道大家在用Python写代码出现报错时是怎样调试的,从报错提示定位回去一步一步check每一行?如果没有IDE或者命令行写代
- 1、Golang指针在介绍Golang指针隐式间接引用前,先简单说下Go 语言的指针 (Pointer),一个指针可以指向任何一个值的内存地
- 之前在训练网络的时候加载数据都是稀里糊涂的放进去的,也没有理清楚里面的流程,今天整理一下,加深理解,也方便以后查阅。pytorch+skle
- 本地一个长期更新的项目,git log突然报错:xxx@yyy:~/android/project/kernel/.git$ git log
- 通过PyFetion可以很方便的使用python来用飞信发送短信,下面贴出代码:from fetion import *import osd
- 在做我的友情链接批量检查工具过程中,碰到一些情况,就是对方网页会用gzip压缩。用gzip压缩的好处是,能压缩网页大小,加快网页的浏览速度,
- 常用树形结构设计总结开发中,经常会遇到树形结构的设计,所谓的树形结构,其实就是数据与关系的设计,本文用来总结常用的树形结构设计1. 递归表i
- 本文介绍了tf.truncated_normal与tf.random_normal的详细用法,分享给大家,具体如下:tf.truncated
- 本文实例讲述了python使用urllib2提交http post请求的方法。分享给大家供大家参考。具体实现方法如下:#!/usr/bin/
- 最近,Facebook设计团队在其位于加州帕罗奥多市(Palo Alto)的总部,提到了他们为2.5亿用户设计的原理和方法。 他们特别强调了
- 需求描述标准网关动态路由功能是重要的一环,将路由、断言以及过滤器信息,持久化到 Mysql 中,通过配置后台页面实现路由、断言、以及过滤器等
- 下面我们将学习两个项目案例代码,分别解决Excel常见场景中的数据筛选问题和数据匹配问题。数据筛选要求我们在表中筛选出符合条件的数据。数据匹
- 背景我们在操作APP应用时,有些需要从一个元素滑动到另外一个元素时,这时候我们无法确定坐标,所以swipe 根据坐标滑动方式就无法使用了,如
- 安装sql server 2008 management,提示错误:Sql2005SsmsExpressFacet 检查是否安装了 SQL
- 最近在做一些email相关的办公自动化项目,发现一个第三方模块imap-tools不错, 网上没有啥相关介绍,所以记录下来.环境: pyth
- 最近使用Python 3.5写了一个GUI小程序,于是想将该写好的程序发布成一个exe文件,供自己单独使用。至于通过安装的方式使用该程序,我
- 谷歌驱动下载地址:http://chromedriver.storage.googleapis.com/index.html一、seleni
- Python中if __name__ == ‘__main__‘作用要搞清楚这个问题,要知道以py作
- 前言由于pycharm自带的pip源网站是国外网址,这就导致了许多国内用户在pycharm中下载其他软件包速度极慢,有时还会跳出下载失败的界