From da861353b4ab88bf69f647f0f74121b7a4bda152 Mon Sep 17 00:00:00 2001 From: YM <479443481@qq.com> Date: 星期一, 25 三月 2024 18:39:46 +0800 Subject: [PATCH] tabBar --- pages/home/home.js | 1 - custom-tab-bar/index.wxml | 4 ++-- custom-tab-bar/index.js | 9 +++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js index aa4b9cd..12e886b 100644 --- a/custom-tab-bar/index.js +++ b/custom-tab-bar/index.js @@ -1,17 +1,14 @@ import TabMenu from './data'; Component({ data: { - selected: 0, + active: 0, list: TabMenu, }, methods: { changeTab(item) { - this.setData({ - selected: item.currentTarget.dataset.num - }) wx.switchTab({ - url: this.data.list[this.data.selected].url.startsWith('/') ? - this.data.list[this.data.selected].url : `/${this.data.list[this.data.selected].url}`, + url: this.data.list[item.currentTarget.dataset.num].url.startsWith('/') ? + this.data.list[item.currentTarget.dataset.num].url : `/${this.data.list[item.currentTarget.dataset.num].url}`, }); } }, diff --git a/custom-tab-bar/index.wxml b/custom-tab-bar/index.wxml index 22debee..cb27aba 100644 --- a/custom-tab-bar/index.wxml +++ b/custom-tab-bar/index.wxml @@ -10,9 +10,9 @@ <view class="tabBarBox"> <view class="tabItem" wx:for="{{list}}" wx:for-item="item" wx:for-index="index" wx:key="index" bindtap="changeTab" data-num="{{index}}"> <view class="custom-tab-bar-wrapper"> - <t-image wx:if="{{selected !== index}}" class="tabImg" src="{{item.icon}}" mode="aspectFill" width="22" height="22" /> + <t-image wx:if="{{active !== index}}" class="tabImg" src="{{item.icon}}" mode="aspectFill" width="22" height="22" /> <t-image wx:else class="tabImg" src="{{item.activeIcon}}" mode="aspectFill" width="22" height="22" /> - <view class="text {{selected == index ? 'activeText' : ''}}">{{ item.text }}</view> + <view class="text {{active == index ? 'activeText' : ''}}">{{ item.text }}</view> </view> </view> </view> \ No newline at end of file diff --git a/pages/home/home.js b/pages/home/home.js index ac08cdd..298b193 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -34,7 +34,6 @@ onShow() { this.loadHomePage(); this.getBannerList() - }, onLoad(options) { -- Gitblit v1.9.1