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:
|
<<: HTML table markup tutorial (37): background image attribute BACKGROUND
>>: In-depth analysis of MySQL query interception
Some friends, when learning about databases, acci...
1. How to represent the current time in MySQL? In...
MySQL5.6 How to create SSL files Official documen...
To install Jenkins on CentOS 8, you need to use t...
1. Prepare the Java environment, jdk1.8 Check whe...
Hello everyone, today we are going to learn about...
1. Multiple borders[1] Background: box-shadow, ou...
After purchasing an Alibaba Cloud server, you nee...
1. Create a new virtual machine from VMware 15.5 ...
...It's like this, today I was going to make a...
I just learned mybatis today and did some simple ...
Type yum install mysql-server Press Y to continue...
In Node.js, a .js file is a complete scope (modul...
The web color picker function in this example use...
Table of contents What is an index? Leftmost pref...