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 标签栏]中 wx.switchTab({url}) 与 that.setData({ value: value, }); 共存会导致显示异常 #2378

Closed
ryiot opened this issue Sep 25, 2023 · 8 comments
Labels
wontfix This will not be worked on

Comments

@ryiot
Copy link

ryiot commented Sep 25, 2023

tdesign-miniprogram 版本

1.2.3

重现链接

No response

重现步骤

image

Component({
data: {
value: 'home',
list: [
{ value: 'home', label: '首页', icon: 'home' },
{ value: 'family', label: '家庭', icon: 'app' },
{ value: 'me', label: '我的', icon: 'user' },
],
},
methods: {
onChange(e) {
let that = this;
const value = e.detail.value;
that.setData({
value: value,
});
const url = '/pages/' + that.data.value + '/index';
wx.switchTab({url})
},
},
});

{{item.label}}

{
"component": true,
"usingComponents": {
"t-tab-bar": "tdesign-miniprogram/tab-bar/tab-bar",
"t-tab-bar-item": "tdesign-miniprogram/tab-bar-item/tab-bar-item"
}
}

image

期望结果

image

实际结果

image

基础库版本

2.19.6

补充说明

No response

@github-actions
Copy link
Contributor

👋 @ryiot,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@ryiot
Copy link
Author

ryiot commented Sep 25, 2023

image image image

@betavs
Copy link
Collaborator

betavs commented Sep 26, 2023

看看是否有报错信息

wx.switchTab({
  url,
  complete: (res) => {
    console.log(res);
  },
});

@ryiot
Copy link
Author

ryiot commented Sep 26, 2023

查看是否有报错信息

wx.switchTab({
  url,
  complete: (res) => {
    console.log(res);
  },
});
image

@ryiot
Copy link
Author

ryiot commented Sep 26, 2023

看看是否有报错信息

wx.switchTab({
  url,
  complete: (res) => {
    console.log(res);
  },
});

无报错信息

@betavs betavs closed this as completed Sep 27, 2023
@betavs betavs reopened this Sep 27, 2023
@betavs
Copy link
Collaborator

betavs commented Sep 27, 2023

自定义 tabBar

image

@betavs betavs added the wontfix This will not be worked on label Sep 27, 2023
@Copy-Hao
Copy link

Copy-Hao commented Nov 4, 2023

自定义 tabBar

image

我试过了用getTabBar()方法去setData还是不行,你可以拉下我的代码去试一下 git clone https://github.com/Copy-Hao/TDesign-TabBar-Issue.git 另外 这个官方文档中的例子是没有这种问题的https://developers.weixin.qq.com/s/ouJiKgm67cHk
刚刚查了一下原因,不是框架问题,是wx小程序官方的自定义TarBar组件实例不是唯一的,他会在每一个新的page下生成一个新的Tarbar组件示例,导致每个页面中的value值都是默认值value="label_1",因此解决方案是在app.js中的globalData中设置一个value变量

  globalData: {
    userInfo: null,
    value: "label_1"
  }

在onchange方法中去更新globalData中的value值

    onChange(e) {
      const data = e.detail
//页面切换 wx.switchTab({ url })
……
      app.globalData.value = data.value
    },

在自定义tarbar中的attach生命周期中执行

  attached: function () {
    this.setData({
      selected: app.globalData.selected
    })
  },

更新后的demo

@ryiot
Copy link
Author

ryiot commented Nov 12, 2023

image
这种方式也可以解决问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants