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

Taro.setTabBarItem() h5不能用 #8580

Closed
daiyuanhao opened this issue Jan 25, 2021 · 3 comments · Fixed by #10658
Closed

Taro.setTabBarItem() h5不能用 #8580

daiyuanhao opened this issue Jan 25, 2021 · 3 comments · Fixed by #10658
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Milestone

Comments

@daiyuanhao
Copy link

相关平台

H5

浏览器版本: Chrome 88.0.4324.104
使用框架: React

复现步骤

Taro.setTabBarItem()

期望结果

执行方法

实际结果

Uncaught (in promise)
{errMsg: "setTabBarItem:fail tabbar item not found"}

环境信息

Taro CLI 3.0.7 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 12.18.3 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.10 - C:\Program Files\nodejs\yarn.CMD
      npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD
@taro-bot2 taro-bot2 bot added F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x labels Jan 25, 2021
@daiyuanhao daiyuanhao changed the title Taro.setTabBarItem() 不能用 Taro.setTabBarItem() h5不能用 Jan 25, 2021
@Fancy-X
Copy link

Fancy-X commented Jun 2, 2021

tag:我3.0.25版本也不能用。。。。。

@LnsooXD
Copy link

LnsooXD commented Jul 1, 2021

Taro 3.1.5

h5中的tarbar部分的函数都不可以使用, 因为它的tabconf从未被初始化,看代码可知, 需要调用initTabBarApis初始化tabconf, 然而他除了在测试用例中被调用过之外, 没有其他地方被调用。

export function initTabBarApis (_App = {}) {
  tabConf = _App.state.__tabs
  App = _App
}

@LnsooXD
Copy link

LnsooXD commented Jul 1, 2021

Taro 3.1.5

我想使用 react-intl-universal 对基于 Taro 的一个老项目进行国际化改造, 但是因为没法在 app.config.ts 中直接引入 react-intl-universal , 故想使用 Taro. setTabBarItem 对TarBar文案进行动态修改。 然而发现在h5上这个函数调用无效。通过观察源码后,我找到一种方法来在运行时修改h5中的TabBar文案,代码示例如下:

      
      // app.ts

       import intl from 'react-intl-universal';

      ...
      ... 

      class App extends Component {
           onLaunch(opts) {
           ... 

            const app: any = Taro.getCurrentInstance().app;
	    const items: any = app.config.tabBar.list;


	    if (Array.isArray(items)) {
		items[0].text = intl.get('a.title');
		items[1].text = intl.get('b.title')
		items[2].text = intl.get('c.title')
	    }
           ...
          }

      }
    
  ...

以上方法可以做到在runtime修改tabbar的文案, 图标和其他属性没有试过

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Archived in project
H5
  
Done
Development

Successfully merging a pull request may close this issue.

4 participants