Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tabbar item个数大于2的时候,下面的切换不会改变 #5709

Closed
wangchangkui opened this issue Jan 27, 2024 · 1 comment
Closed

Comments

@wangchangkui
Copy link

重现链接

当使用van-tabbar的时候,切换页面的时候,理论上应该会随着页面改变,但是当tabbar的数量大于2的时候,切换似乎并没有改变颜色。
我的代码示例如下:
// custom-tab-bar/index.wxml,;

{{
item.text
}}

// custom-tab-bar/index.js
Component({

/**

  • 页面的初始数据
    /
    data: {
    active:0,
    list: [
    {
    icon: 'home-o',
    text: '首页',
    url: '/pages/index/index'
    },
    {
    icon: 'star-o',
    text: '分类',
    url: '/pages/favorites/favorites'
    },
    {
    icon: 'shopping-cart-o',
    text: '购物车',
    url: '/pages/shopcar/shopcar'
    },
    {
    icon: 'friends-o',
    text: '我的',
    url: '/pages/me/index'
    }
    ]
    },
    methods: {
    /
    *
    • 切换tabar

    • @param {event} event 当切换事件发生
      */
      onChange(event) {
      this.setData({ active: event.detail });

       wx.switchTab({
       	url: this.data.list[event.detail].url
       });
      

      },

      init() {
      const page = getCurrentPages().pop();
      this.setData({
      active: this.data.list.findIndex(item => item.url === /${page.route})
      });
      }
      }

})
app.json
"tabBar": {
"custom": true,
"color": "#000000",
"selectedColor": "#ffffff",
"backgroundColor": "#000000",
"list": [
{
"pagePath": "pages/index/index",
"text": "首页"
},
{
"pagePath": "pages/favorites/favorites",
"text": "分类"
},
{
"pagePath": "pages/shopcar/shopcar",
"text": "购物车"
},
{
"pagePath": "pages/me/index",
"text": "我的"
}
]
}
image

Vant Weapp 版本

1.10.16

描述一下你遇到的问题。

van-tabbar 组件

重现步骤

测试代码可以参考你们提供的wxapp示例,但是需要多添加2个tabbar

设备/浏览器

No response

@wangchangkui
Copy link
Author

已经解决了,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants