WeChat applet custom bottom navigation bar component

WeChat applet custom bottom navigation bar component

This article example shares the specific implementation code of the bottom navigation bar component of the WeChat applet for your reference. The specific content is as follows

1. Create a new tabbar.vue (defined custom navigation bar component) under the file price of the public component of your own project

<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:{ // current page index
    type:Number,
    default:0
   },
    },
    data() {
      return {
        selectedIndex: 0,
        tabList: [
          {
            name: "Home",
            iconPath: require("../../../static/image/img/tab-home-nor.png"),
            iconActivePath: require("../../../static/image/img/tab-home-sel.png"),
          path: "/pages/index/index",
          },
          {
            name: "Shopping Cart",
            iconPath: require("../../../static/image/img/tab-cart-nor.png"),
            iconActivePath: require("../../../static/image/img/tab-cart-sel.png"),
            path: "/pages/cart/cartEdit",
          },
          {
            name: "My",
            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. Add code to the pages.json file in the project to ensure that wx.switchTab in tabbar.vue can be used normally. The code is as follows:

"tabBar": {
    "selectedColor": "#EE2F51",
    "list": [{
      "pagePath": "pages/index/index",
      "text": "Home",
      "iconPath": "static/image/img/tab-home-nor.png",
      "selectedIconPath": "static/image/img/tab-home-sel.png"
    },{
      "pagePath": "pages/cart/cartEdit",
      "text": "Shopping Cart",
      "iconPath": "static/image/img/tab-cart-nor.png",
      "selectedIconPath": "static/image/img/tab-cart-sel.png"
    },{
      "pagePath": "pages/mine/mine",
      "text": "My",
      "iconPath": "static/image/img/tab-my-nor.png",
      "selectedIconPath": "static/image/img/tab-my-sel.png"
    }]
  },

3. Register custom components globally in main.js

import tabBar from "./customComponents/commonComponents/tabBar/index.vue";

//Change your component position, the index.vue here is the tabbar.vue mentioned earlier
Vue.component("tabBar", tabBar);

4. Introduce the registered component on the page where the navigation bar is needed

//Introduce the navigation bar component to the page <tabBar :current=item_index></tabBar>
 
//Mark status, yes the navigation bar can display different activation status according to the page data() {
      return {
        item_index: 0,
      }
}
 
//Hide WeChat's built-in navigation bar onLoad() {
      wx.hideTabBar();
},

5. Display effect

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • WeChat Mini Program Tutorial Series: Setting the Title Bar and Navigation Bar (7)
  • WeChat applet development top navigation bar example code
  • Detailed explanation of how to set the bottom navigation column of WeChat applet
  • WeChat applet custom header navigation bar and navigation bar background image navigationStyle problem
  • Implementation code of the top navigation bar in WeChat applet
  • Detailed explanation of WeChat applet capsule button return | home page custom navigation bar function
  • WeChat applet top navigation bar sliding tab effect
  • WeChat applet custom navigationBar top navigation bar adapts to all models (with complete case)
  • WeChat applet implements left sliding navigation bar
  • WeChat applet realizes the effect of navigation bar tab

<<:  HTML table markup tutorial (37): background image attribute BACKGROUND

>>:  In-depth analysis of MySQL query interception

Recommend

Mysql varchar type sum example operation

Some friends, when learning about databases, acci...

The difference and usage of datetime and timestamp in MySQL

1. How to represent the current time in MySQL? In...

MySQL configuration SSL master-slave replication

MySQL5.6 How to create SSL files Official documen...

How to install Jenkins on CentOS 8

To install Jenkins on CentOS 8, you need to use t...

Super detailed MySQL8.0.22 installation and configuration tutorial

Hello everyone, today we are going to learn about...

Tips for implementing multiple borders in CSS

1. Multiple borders[1] Background: box-shadow, ou...

VMware 15.5 version installation Windows_Server_2008_R2 system tutorial diagram

1. Create a new virtual machine from VMware 15.5 ...

Today I encountered a very strange li a click problem and solved it myself

...It's like this, today I was going to make a...

Solve the splicing problem of deleting conditions in myBatis

I just learned mybatis today and did some simple ...

How to install MySQL via SSH on a CentOS VPS

Type yum install mysql-server Press Y to continue...

Summary of the differences between global objects in nodejs and browsers

In Node.js, a .js file is a complete scope (modul...

Using CSS3 and JavaScript to develop web color picker example code

The web color picker function in this example use...

How to design and optimize MySQL indexes

Table of contents What is an index? Leftmost pref...