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
Run the command: glxinfo | grep rendering If the ...
Effect: When the slideshow moves in one direction...
Table of contents introduction 1. Code to start t...
There are many attributes in CSS. Some attributes...
How to uninstall Mysql perfectly? Follow the step...
1. Concept They are all attributes of Element, in...
The security issues encountered in website front-...
As shown below: As shown above, just replace it. ...
Linux system version: CentOS7.4 MySQL version: 5....
I recently started learning database, and I feel ...
Preface Basically, programmers in the workplace u...
Because li is a block-level element and occupies ...
MVCC MVCC (Multi-Version Concurrency Control) is ...
When using MySQL, many developers often perform f...
Table of contents 1. Server 2. Client 3. Testing ...