简体   繁体   中英

Why does Onsen UI throw me errors?

I am building a PWA using React and Onsen UI with react-onsenui bindings. I try to become comfortable with the Tabbar playing around with the official example shown on Onsen UI's website. My code at the moment looks like this (pretty simple):

import React, { Component } from 'react';
import { Page, Tabbar, Tab } from 'react-onsenui';

import 'onsenui/css/onsenui.css';
import 'onsenui/css/onsen-css-components.css';

import ScreenOne from './screenOne';
import ScreenTwo from './screenTwo';

class App extends Component {

  state = {
    index: 0,
  }

  render() {
    return (
      <Page>
        <Tabbar
          onPreChange={({index}) => this.setState({index})}
          onPostChange={() => console.log('postChange')}
          onReactive={() => console.log('postChange')}
          position='bottom'
          index={this.state.index}
          renderTabs={(activeIndex, tabbar) => [
            {
              content: <ScreenOne key="Home" title="Home" active={activeIndex === 0} tabbar={tabbar} />,
              tab: <Tab key="Home" label="Home" icon="md-home" />
            },
            {
              content: <ScreenTwo key="Settings" title="Settings" active={activeIndex === 1} tabbar={tabbar} />,
              tab: <Tab key="Settings"  label="Settings" icon="md-settings" />
            }]
          }
        />
      </Page>
    );
  }
}

export default App;

However it does not work. I can click a tab once but that's it. The console throws me errors.

On initial page load

Uncaught TypeError: el._show is not a function
    at onsenui.js:31327
    at run (setImmediate.js:48)
    at runIfPresent (setImmediate.js:83)
    at onGlobalMessage (setImmediate.js:125)

On tab click

onsenui.js:31057 Uncaught (in promise) TypeError: prevTab.pageElement._hide is not a function
    at HTMLElement._onPreChange (onsenui.js:31057)
    at Swiper._changeTo (onsenui.js:15695)
    at Swiper.setActiveIndex (onsenui.js:15479)
    at onsenui.js:31233

I am completely stuck at the moment. Thx for help.

Could you post your ScreenOne and ScreenTwo component? check whether these 2 components are wrapped by 'Page' tag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM